我發現了一個快速的工作圍繞這在一定程度適合我的目的。我想我會在這裏發佈它,以防其他人感到好奇,並且可能對他們有所幫助。它涉及繼承AxisItem並指定tickStrings。它不能很好地工作,因爲它保持與底部主軸線相同的嘀嗒聲位置,但它至少應該讓我知道我在看什麼。
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
class CustomAxis(pg.AxisItem):
def tickStrings(self, values, scale, spacing):
return ['{:.4f}'.format(1./i) for i in values]
pg.mkQApp()
pw = pg.PlotWidget()
pw.show()
pw.setWindowTitle('pyqtgraph example: MultipleXAxes')
p1 = pw.plotItem
p1.setLabels(left='axis 1')
# Get rid of the item at the grid position where the top should be
p1.layout.removeItem(p1.getAxis('top'))
# make our own, setting the parent and orientation
caxis = CustomAxis(orientation='top', parent=p1)
caxis.setLabel('inverted')
caxis.linkToView(p1.vb)
# set the new one for internal plotitem
p1.axes['top']['item'] = caxis
# and add it to the layout
p1.layout.addItem(caxis, 1, 1)
p1.plot(np.arange(1, 7), [1,2,4,8,16,32])
#p2.addItem(pg.PlotCurveItem(1./np.arange(1, 7), [1,2,4,8,16,32], pen='b'))
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
很明顯,返回值應該被任何與兩軸相關的函數取代。
我有一個類似的問題,但在我的情況下,它也取決於如何改變軸的情節。我用以下方式解決了這個問題,但感覺不正確。該問題的鏈接http://stackoverflow.com/questions/43545364/pyqtgraph-imageitems-new-axis-labels。也許你可以幫助我? –