PyQtGraph Basic Realization[2]
Profile
Last Time We managed to add logic wave in the GraphicsLayoutWidget. Today We Try to add Curve for the GraphicsLayoutWidgets.
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。First Step
We Need to set the PlotItem clickable as well
plt1.plot(list1,pen=pg.mkPen(color='#AA0000', width=1),name="Red Line")
curvePlot.curve.setClickable(True)
Second Step
Add LineRegionItem to the first plot
lr = pg.LinearRegionItem([1, 30], bounds=[0, 100], movable=True) plt1.addItem(lr)
About The LinearRegionItem
__init__(values=(0, 1), orientation='vertical', brush=None, pen=None, hoverBrush=None, hoverPen=None, movable=True, bounds=None, span=(0, 1), swapMode='sort')
values | A list of the positions of the lines in the region. These are not limits; limits can be set by specifying bounds. |
orientation | Options are ‘vertical’ or ‘horizontal’, indicating the The default is ‘vertical’, indicating that the |
brush | Defines the brush that fills the region. Can be any arguments that are valid for mkBrush . Default is transparent blue. |
pen | The pen to use when drawing the lines that bound the region. |
hoverBrush | The brush to use when the mouse is hovering over the region. |
hoverPen | The pen to use when the mouse is hovering over the region. |
movable | If True, the region and individual lines are movable by the user; if False, they are static. |
bounds | Optional [min, max] bounding values for the region |
span | Optional [min, max] giving the range over the view to draw the region. For example, with a vertical line, use span=(0.5, 1) to draw only on the top half of the view. |
swapMode | Sets the behavior of the region when the lines are moved such that their order reverses: * “block” means the user cannot drag one line past the other * “push” causes both lines to be moved if one would cross the other * “sort” means that lines may trade places, but the output of getRegion always gives the line positions in ascending order.
The default is “sort”. |
Third Step
Add single Line
line = pg.InfiniteLine(angle=90, movable=True) plt1.addItem(line) line.setBounds([0, 200])
About The InfiniteLine
__init__(pos=None, angle=90, pen=None, movable=False, bounds=None, hoverPen=None, label=None, labelOpts=None, span=(0, 1), markers=None, name=None)
Arguments: | |
pos | Position of the line. This can be a QPointF or a single value for vertical/horizontal lines. |
angle | Angle of line in degrees. 0 is horizontal, 90 is vertical. |
pen | Pen to use when drawing line. Can be any arguments that are valid for mkPen . Default pen is transparent yellow. |
hoverPen | Pen to use when the mouse cursor hovers over the line. Only used when movable=True. |
movable | If True, the line can be dragged to a new position by the user. |
bounds | Optional [min, max] bounding values. Bounds are only valid if the line is vertical or horizontal. |
hoverPen | Pen to use when drawing line when hovering over it. Can be any arguments that are valid for mkPen . Default pen is red. |
label | Text to be displayed in a label attached to the line, or None to show no label (default is None). May optionally include formatting strings to display the line value. |
labelOpts | A dict of keyword arguments to use when constructing the text label. See InfLineLabel . |
span | Optional tuple (min, max) giving the range over the view to draw the line. For example, with a vertical line, use span=(0.5, 1) to draw only on the top half of the view. |
markers | List of (marker, position, size) tuples, one per marker to display on the line. See the addMarker method. |
name | Name of the item |
更多精彩