2

pyqtgraph でスミス チャートをプロットしようとしています。半径 = 1 の実際の円で仮想円を表す楕円アイテムをクリップする方法があるかどうかを知りたいです。しかし、このようにして、円の垂直線と水平線もプロットされます。matplotlib には set_clip_path() というメソッドがありますが、pyqtgraph にこのようなものがあるかどうか知っていますか?

import pyqtgraph as pg

plot = pg.plot()

plot.setAspectLocked()
plot.addLine(y=0)

#vector for real circle
rline = [0.2, 0.5, 1.0, 2.0, 5.0]
#vector for imaginary
xline = [0.2, 0.5, 1, 2, 5]

circle1 = pg.QtGui.QGraphicsEllipseItem(1, -1, -2, 2)
circle1.setPen(pg.mkPen(1))
plot.addItem(circle1)

for r in rline:
    raggio = 1./(1+r)
    circle = pg.QtGui.QGraphicsEllipseItem(1, -raggio, -raggio*2, raggio*2)
    circle.setPen(pg.mkPen(0.2))
    plot.addItem(circle)

for x in xline:
    #printing the imaginary circle
    circle = pg.QtGui.QGraphicsEllipseItem(x + 1, 0, -x*2, x*2)
    circle.setPen(pg.mkPen(0.2))
    circle.setStartAngle(1440)
    circle.setSpanAngle(1440)
    plot.addItem(circle)

編集

それが私の最終的なコードです

plot.setAspectLocked()
plot.setXRange(-1,1, padding = 0)
plot.setYRange(-1,1, padding = 0)
#plot.addLine(y=0)

rline = [0.2, 0.5, 1.0, 2.0, 5.0]
xline = [0.2, 0.5, 1, 2, 5]

circle1 = pg.QtGui.QGraphicsEllipseItem(1, -1, -2, 2)
circle1.setPen(pg.mkPen('w', width=0))
circle1.setFlag(circle1.ItemClipsChildrenToShape)
plot.addItem(circle1)

pathItem = pg.QtGui.QGraphicsPathItem()
path = pg.QtGui.QPainterPath()
path.moveTo(1, 0)

for r in rline:
    raggio = 1./(1+r)
    path.addEllipse(1, -raggio, -raggio*2, raggio*2)

for x in xline:
    path.arcTo(x + 1, 0, -x*2, x*2, 90, -180)
    path.moveTo(1, 0)
    path.arcTo(x + 1, 0, -x*2, -x*2, 270, 180)

pathItem.setPath(path)
pathItem.setPen(pg.mkPen('g', width = 0.2))
pathItem.setParentItem(circle1)

`

4

1 に答える 1

2

クリッピングはサポートされていますが、おそらく最適なオプションではありません。いくつかの可能性:

  1. QGraphicsPathItemをQPainterPath.arcToと組み合わせて使用​​して、放射状の線なしで円弧を描画します。これにより、多くのアイテムを追加するのではなく、1 つのアイテムに複数のアークを追加できるようになり、パフォーマンスが向上するはずです。

  2. PlotCurveItemarrayToQPathなどを使用して、独自の円弧を手動で描画します。引数を使用するconnectと、1 つのアイテムに複数の別々のアークを再び生成できます。

  3. クリッピングは Qt によって処理されます。QGraphicsItem.itemClipsToShape と QGraphicsItem.itemClipsChildrenToShapeを参照してください。注意: これを使用する場合は、クリッピング オブジェクトのペン幅を 0 に設定する必要があります (Qt は、幅 > 0 のコスメティック ペンを部分的にしかサポートしていません)。例:

    import pyqtgraph as pg
    plot = pg.plot()
    
    e1 = pg.QtGui.QGraphicsEllipseItem(0, 0, 4, 4)
    # MUST have width=0 here, or use a non-cosmetic pen:
    e1.setPen(pg.mkPen('r', width=0))
    e1.setFlag(e1.ItemClipsChildrenToShape)
    plot.addItem(e1)
    
    e2 = pg.QtGui.QGraphicsEllipseItem(2, 2, 4, 4)
    e2.setPen(pg.mkPen('g'))
    e2.setParentItem(e1)
    
于 2014-12-15T15:43:41.847 に答える