2016-12-10 5 views
0
아래

점수의 튜플 (점수 및 빈도)PyQtGraph는 - 축 간격을 설정하는 방법

def initialise_chart(self, scores): 

    pg.setConfigOption("background", "w") 
    pg.setConfigOption("foreground", "k") 

    results_graph = pg.PlotWidget() 
    self.chart_results.addWidget(results_graph) 
    results_graph.plot([i[0] for i in scores], [i[1] for i in scores], pen={'color': "#006eb4"}) 
    results_graph.setLabels(left="Frequency", bottom="Scores") 
    results_graph.setXRange(0, self.max_mark, padding=0) 

이 다음과 같은 그래프를 생성 목록을 기반으로 그래프를 만들 내가 작성한 함수 : enter image description here

y 축의 간격을 설정하여 숫자가 1 씩 증가하지만 범위는 자동으로 조정됩니까? 예. 예 그래프의 y 축에 표시되는 유일한 수는 0, 1, 것 2

답변

1

당신은 예를함으로써 AxisItem에 틱을 변경해야합니다

import pyqtgraph as pg 
import numpy as np 
from pyqtgraph.Qt import QtCore, QtGui 

app = pg.mkQApp() 

pw = pg.PlotWidget(title="Example") 
x = np.arange(20) 
y = x**2/150 
pw.plot(x=x, y=y, symbol='o') 
pw.show() 
pw.setWindowTitle('Example') 

ax = pw.getAxis('bottom') # This is the trick 
dx = [(value, str(value)) for value in list((range(int(min(x.tolist())), int(max(x.tolist())+1))))] 
ax.setTicks([dx, []]) 

ay = pw.getAxis('left') # This is the trick 
dy = [(value, str(value)) for value in list((range(int(min(y.tolist())), int(max(y.tolist())+1))))] 
ay.setTicks([dy, []]) 

if __name__ == '__main__': 
    import sys 

    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): 
     QtGui.QApplication.instance().exec_() 

전 :

enter image description here

후 :

enter image description here

+0

도와 줘서 고마워. – Ronikos