PyDMTimePlot
- class pydm.widgets.timeplot.PyDMTimePlot(parent=None, init_y_channels=[], plot_by_timestamps=True, background='default', bottom_axis=None)[source]
Bases:
BasePlot
,updateMode
PyDMTimePlot is a widget to plot one or more channels vs. time.
Each curve can plot either a Y-axis waveform vs. its indices, or a Y-axis waveform against an X-axis waveform.
- Parameters:
parent (optional) – The parent of this widget.
init_y_channels (list) – A list of scalar channels to plot vs time.
plot_by_timestamps (bool) – If True, the x-axis shows timestamps as ticks, and those timestamps scroll to the left as time progresses. If False, the x-axis tick marks show time relative to the current time.
background (optional) – The background color for the plot. Accepts any arguments that pyqtgraph.mkColor will accept.
bottom_axis (AxisItem, optional) – Will set the bottom axis of this plot to the input axis. If not set, will default to either a TimeAxisItem if plot_by_timestamps is true, or a regular AxisItem otherwise
- addLegendItem(item, pv_name, force_show_legend=False)[source]
Add an item into the graph’s legend.
- Parameters:
item (TimePlotCurveItem) – A curve being plotted in the graph
pv_name (str) – The PV channel
force_show_legend (bool) – True to make the legend to be displayed; False to just add the item, but do not display the legend.
- addYChannel(y_channel=None, plot_style=None, name=None, color=None, lineStyle=None, lineWidth=None, symbol=None, symbolSize=None, barWidth=None, upperThreshold=None, lowerThreshold=None, thresholdColor=None, yAxisName=None, useArchiveData=False, **kwargs)[source]
Adds a new curve to the current plot
- Parameters:
y_channel (str) – The PV address
plot_style (str, optional) – The style in which to render the data, either ‘Line’ or ‘Bar’
name (str) – The name of the curve (usually made the same as the PV address)
color (QColor) – The color for the curve
lineStyle (str) – The line style of the curve, i.e. solid, dash, dot, etc.
lineWidth (int) – How thick the curve line should be
symbol (str) – The symbols as markers along the curve, i.e. circle, square, triangle, star, etc.
symbolSize (int) – How big the symbols should be
barWidth (float, optional) – Width of any bars drawn on the plot
upperThreshold (float, optional) – Bars that are above this value will be drawn in the threshold color
lowerThreshold (float, optional) – Bars that are below this value will be drawn in the threshold color
thresholdColor (QColor, optional) – Color to draw bars that exceed either threshold
yAxisName (str) – The name of the y axis to associate with this curve. Will be created if it doesn’t yet exist
- Returns:
new_curve – The newly created curve.
- Return type:
- autoRangeY
Whether or not the Y-axis automatically rescales to fit the data. If true, the values in minYRange and maxYRange are ignored.
- bufferSize
Get the size of the data buffer for the entire chart.
- Returns:
size – The chart’s data buffer size.
- Return type:
int
- curves
Dump the current list of curves and each curve’s settings into a list of JSON-formatted strings.
- Returns:
settings – A list of JSON-formatted strings, each containing a curve’s settings
- Return type:
list
- enableCrosshair(is_enabled, starting_x_pos=-30, starting_y_pos=0, vertical_angle=90, horizontal_angle=0, vertical_movable=False, horizontal_movable=False)[source]
Display a crosshair on the graph.
- Parameters:
is_enabled (bool) – True is to display the crosshair; False is to hide it.
starting_x_pos (float) – The x position where the vertical line will cross
starting_y_pos (float) – The y position where the horizontal line will cross
vertical_angle (int) – The angle of the vertical line
horizontal_angle (int) – The angle of the horizontal line
vertical_movable (bool) – True if the user can move the vertical line; False if not
horizontal_movable (bool) – True if the user can move the horizontal line; False if not
- findCurve(pv_name)[source]
Find a curve from a graph’s curve list.
- Parameters:
pv_name (str) – The curve’s PV address.
- Returns:
curve – The found curve, or None.
- Return type:
- getAutoRangeX()[source]
A return type of bool is a simple yes/no if the x-axis has auto range set. A float from 0.0 - 1.0 also means True, but only showing a percentage of the data corresponding to the value.
- getBufferSize()[source]
Get the size of the data buffer for the entire chart.
- Returns:
size – The chart’s data buffer size.
- Return type:
int
- getCurves()[source]
Dump the current list of curves and each curve’s settings into a list of JSON-formatted strings.
- Returns:
settings – A list of JSON-formatted strings, each containing a curve’s settings
- Return type:
list
- getTimeSpan()[source]
The extent of the x-axis of the chart, in seconds. In other words, how long a data point stays on the plot before falling off the left edge.
- Returns:
time_span – The extent of the x-axis of the chart, in seconds.
- Return type:
float
- getUpdateInterval()[source]
Get the update interval for the chart.
- Returns:
interval – The update interval of the chart.
- Return type:
float
- maxYRange
Maximum Y-axis value visible on the plot.
- minYRange
Minimum Y-axis value visible on the plot.
- refreshCurve(curve)[source]
Remove a curve currently being plotted on the timeplot, then redraw that curve, which could have been updated with a new symbol, line style, line width, etc.
- Parameters:
curve (TimePlotCurveItem) – The curve to be re-added.
- removeLegendItem(pv_name)[source]
Remove an item from the legend.
- Parameters:
pv_name (str) – The PV channel, used to search for the legend item to remove.
- removeYChannel(curve)[source]
Remove a curve from the graph. This also stops update the timer associated with the curve.
- Parameters:
curve (TimePlotCurveItem) – The curve to be removed.
- removeYChannelAtIndex(index)[source]
Remove a curve from the graph, given its index in the graph’s curve list.
- Parameters:
index (int) – The curve’s index from the graph’s curve list.
- resetBufferSize()[source]
Reset the data buffer size of the chart, and each of the chart’s curve’s data buffer, to the minimum
- setAutoRangeX(value)[source]
Set the auto range property for the x-axis.
- Parameters:
value (bool or float) – False means no autorange, True means show all data. A float between 0.0 and 1.0 means only show a percentage of the data (for example, 0.75 = 75% of data will be visible)
- setAutoScroll(enable: bool = False, timespan: float = 60, padding: float = 0.1, refresh_rate: int = 5000)[source]
Enable/Disable autoscrolling along the x-axis. This will (un)pause the autoscrolling QTimer, which calls the auto_scroll slot when time is up.
- Parameters:
enable (bool, optional) – Whether or not to start the autoscroll QTimer, by default False
timespan (float, optional) – The timespan to set for autoscrolling along the x-axis in seconds, by default 60
padding (float, optional) – The size of the empty space between the data and the sides of the plot, by default 0.1
refresh_rate (int, optional) – How often the scroll should occur in milliseconds, by default 5000
- setBufferSize(value)[source]
Set the size of the data buffer of the entire chart. This will also update the same value for each of the data buffer of each chart’s curve.
- Parameters:
value (int) – The new buffer size for the chart.
- setCurves(new_list)[source]
Add a list of curves into the graph.
- Parameters:
new_list (list) – A list of JSON-formatted strings, each contains a curve and its settings
- setTimeSpan(value)[source]
Set the extent of the x-axis of the chart, in seconds. In aynchronous mode, the chart will allocate enough buffer for the new time span duration. Data arriving after each duration will be recorded into the buffer having been rotated.
- Parameters:
value (float) – The time span duration, in seconds, to allocate enough buffer to collect data for, before rotating the buffer.
- setUpdateInterval(value)[source]
Set a new update interval for the chart and update its data buffer size.
- Parameters:
value (float) – The new update interval value.
- timeSpan
The extent of the x-axis of the chart, in seconds. In other words, how long a data point stays on the plot before falling off the left edge.
- Returns:
time_span – The extent of the x-axis of the chart, in seconds.
- Return type:
float
- to_dict() OrderedDict [source]
Adds attribute specific to TimePlot to add onto BasePlot’s to_dict. This helps to recreate the Plot Config if we import a save file of it
- updateInterval
Get the update interval for the chart.
- Returns:
interval – The update interval of the chart.
- Return type:
float
- updateMode
The updateMode to be used as property to set plot update mode.
- Return type:
updateMode
TimePlotCurveItem
- class pydm.widgets.timeplot.TimePlotCurveItem(channel_address=None, plot_by_timestamps=True, plot_style='Line', **kws)[source]
Bases:
BasePlotCurveItem
TimePlotCurveItem represents a single curve in a time plot.
It is used to plot a scalar value vs. time. In addition to the parameters listed below, TimePlotCurveItem accepts keyword arguments for all plot options that pyqtgraph.PlotDataItem accepts.
- Parameters:
channel_address (str) – The address to of the scalar data to plot.
plot_by_timestamps (bool) – If True, the x-axis shows timestamps as ticks, and those timestamps scroll to the left as time progresses. If False, the x-axis tick marks show time relative to the current time.
plot_style (str, optional) – Currently one of either ‘Line’ or ‘Bar’. Determines how data points for this curve will be plotted. Defaults to a line based plot if not set
color (QColor, optional) – The color used to draw the curve line and the symbols.
lineStyle (int, optional) – Style of the line connecting the data points. Must be a value from the Qt::PenStyle enum (see http://doc.qt.io/qt-5/qt.html#PenStyle-enum).
lineWidth (int, optional) – Width of the line connecting the data points.
**kws (dict) – Additional parameters supported by pyqtgraph.PlotDataItem, like ‘symbol’ and ‘symbolSize’.
- asyncUpdate()[source]
Updates the latest data read from the buffered variable into the data buffer, together with the timestamp when this happens. Also increments the accumulated point counter.
- insert_live_data(data: ndarray) None [source]
Inserts data directly into the live buffer.
Example use case would be pausing the gathering of data and filling the buffer with missed data.
- Parameters:
data (np.ndarray) – A numpy array of shape (2, length_of_data). Index 0 contains timestamps and index 1 contains the data observations.
- property maxY
Get the maximum y-value so far in the same plot. This is useful to scale the y-axis for a selected curve.
- Returns:
The maximum y-value collected so far for this current curve.
- Return type:
float
- max_x()[source]
Provide the the most recent timestamp accumulated from the data buffer. This is useful for scaling the x-axis.
- Returns:
The timestamp of the most recent data point recorded into the data buffer.
- Return type:
float
- property minY
Get the minimum y-value so far in the same plot. This is useful to scale the y-axis for a selected curve.
- Returns:
The minimum y-value collected so far for this current curve.
- Return type:
float
- min_x()[source]
Provide the the oldest valid timestamp from the data buffer.
- Returns:
The timestamp of the most recent data point recorded into the data buffer.
- Return type:
float
- receiveNewValue(new_value)[source]
Rotate and fill the data buffer when a new value is available.
For Synchronous mode, write the new value into the data buffer immediately, and increment the accumulated point counter. For Asynchronous, write the new value into a temporary (buffered) variable, which will be written to the data buffer when asyncUpdate is called.
This method is usually called by a PyDMChannel when it updates. You can call it yourself to inject data into the curve.
- Parameters:
new_value (float) – The new y-value.
- redrawCurve(min_x: Optional[float] = None, max_x: Optional[float] = None)[source]
Redraw the curve with the new data.
If plot by timestamps, plot the x-axis with the timestamps as the ticks.
On the other hand, if plot by relative time, take the time diff from the starting time of the curve, and plot the data to the time diff position on the x-axis.
- Parameters:
min_x (float, optional) – The minimum timestamp to render when plotting as a bar graph.
max_x (float, optional) – The maximum timestamp to render when plotting as a bar graph.
- setUpdatesAsynchronously(value)[source]
Check if value is from updatesAsynchronously(bool) or updateMode(int)