Is the following what you want? It has the x axis is on the left side,
labeled as the x axis and increases as you go up. The y axis is on the
bottom, is labeled the y axis and increases *to the left*.
Done by setting the plotwidget to have invertX=true which is actually a
property of the PlotItem created by the plotwidget. Then the graph is
rotated 90 degrees and the PlotItem axis's are labeled as you want.
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
app = QtGui.QApplication([])
mw = QtGui.QMainWindow()
win = pg.PlotWidget()
x = np.arange(0, 2*np.pi, 0.1)
y = np.sin(x)
l = pg.PlotDataItem(x=x,y=y)
win.addItem(l)
win.getPlotItem().invertX(True)
cw = QtGui.QWidget() # GENERIC WIDGET AS CENTRAL WIDGET (inside
main window)
lay = QtGui.QGridLayout()
cw.setLayout(lay)
lay.addWidget(win)
l.rotate(90)
ax = win.getPlotItem().getAxis('left')
ax.setLabel('Y')
ax = win.getPlotItem().getAxis('bottom')
ax.setLabel('X')
mw.setCentralWidget(cw)
mw.show()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
On Monday, July 24, 2017 at 10:31:19 AM UTC-6, m has wrote:
>
> Is there any way to swap x-axis and y-axis in plot. I need a vertical
> x-axis and horizontal y-axis. I can not simply plot(y,x) as I need to set
> alot of other properties as well. I have been searching for two days but no
> avail. I rotated the ViewBox, but it changes the x-axis and y-axis labels.
>
> Thank you.
>
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/ec063b72-20e0-413c-a842-57d8387b2a9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.