PyQtGraphで線種(スタイル・色・太さ)の設定です。
ソースです。
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pyqtgraph.exporters
app = QtGui.QApplication([])
win = pg.GraphicsLayoutWidget(size=(500, 300), title = '雛形')
p = win.addPlot(row=0, col=0)
"""
style
Qt.SolidLine, Qt.DashLine, Qt.DotLine, Qt.DashDotLine, Qt.DashDotDotLine, Qt.CustomDashLine
"""
p.addLegend()
p.plot([0,1], [1,1], pen = pg.mkPen( style = QtCore.Qt.SolidLine, width=5), antialias = True )
p.plot([0,1], [2,2], pen = pg.mkPen( style = QtCore.Qt.DashLine), antialias = True)
p.plot([0,1], [3,3], pen = pg.mkPen( style = QtCore.Qt.DotLine), antialias = True)
p.plot([0,1], [4,4], pen = pg.mkPen( style = QtCore.Qt.DashDotLine), antialias = True)
p.plot([0,1], [5,5], pen = pg.mkPen( color = 'y', style = QtCore.Qt.DashDotDotLine), antialias = True)
pen = pg.mkPen(style = QtCore.Qt.CustomDashLine)
pen.setDashPattern([10, 40, 50, 40])
pen.setWidth(3)
pen.setColor(QtGui.QColor(255, 0, 0))
p.plot([0,1], [6,6], pen = pen, antialias = True, name='CustomDashLine')
win.show()
# pngファイルにグラフを出力
# exportersの直前に pg.QtGui.QApplication.processEvents() を呼ぶ!
pg.QtGui.QApplication.processEvents()
exporter = pg.exporters.ImageExporter(win.scene())
exporter.export("graph03.png")
app.exec_()
print('finished.')
plotの引数として設定することができます。また、 pen = pg.mkPen(style = QtCore.Qt.CustomDashLine)
のようにpenを定義して
plotに渡す方法もあります。 スタイルはQt.SolidLine, Qt.DashLine, Qt.DotLine, Qt.DashDotLine, Qt.DashDotDotLine, Qt.CustomDashLine
があります。 色はplot内ではcolor,
penオブジェクトでは setColorで指定します。 太さはplot内ではwidth, penオブジェクトでは setWidthで指定します。
Matplotlibでのlabelはnemeです。これを表示するには、 p.addLegend() を先に書きます。
結果として簡単な情報ですが、PyQtGraphは本家本元のコピペみたいはページばかりで調べるのに時間がかかりました。
本家本元もサンプルを見てくれみたいで丁寧な解説ではないです。
|