2016-12-10 51 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

数字が1ずつ増加するようにy軸の間隔を設定する方法はありますか?ただし、範囲は自動スケールされていますか?例えば。例えば、グラフのy軸に表示されるだけの数が0、1、2

答えて

1

だろうあなたは一例で、AxisItem上の目盛りを変更する必要があります。

enter image description here

:前

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

+0

あなたに助けてくれてありがとう – Ronikos

関連する問題