daplis_rtp.gui.canvas.base module
The one plot widget every tab draws on.
There used to be three of these - plot_figure, plot_figure_dual
and plot_figure_MZI - which between them were the same eighty lines
copied out three times, with the differences that mattered (a boundary
line here, a second y-axis there) buried among the differences that did
not (one called its styling method setplotparameters, another
_setplotparameters). A change to the look had to be made three
times and usually was not.
Here there is one base class holding the figure, the toolbar, the sizing and the theme, and one small subclass per kind of plot saying only what that plot draws.
The pattern is store, then render. A tab hands in data; the canvas keeps it and draws. When the theme changes the canvas draws the same data again. That is what makes a colour picked in Preferences appear on a plot that was drawn ten minutes ago, and it is why the canvases hold no copies of theme colours.
- class daplis_rtp.gui.canvas.base.BaseCanvas(parent=None, width=7, height=4, dpi=100)[source]
Bases:
QWidgetA matplotlib figure, its toolbar, and the current theme.
Subclasses override
draw_data()to say what to draw, andx_label/y_labelto say what the axes are. Nothing else should need overriding.- property fontsize
- glow(gradient=True)[source]
The look the application is known for, when the theme wants it.
Off by default in every theme but “Cyberpunk”, because it is not free: each line is redrawn several times over, which is felt on a stream refreshing as fast as the files arrive.
- render()[source]
Draw the stored data in the current theme.
Everything is drawn inside one
rc_context: matplotlib reads the parameters when an artist is created, so styling has to wrap the drawing rather than follow it. The old code pushed values into the globalplt.rcParamsfrom inside each draw, which meant whichever canvas drew last decided how the others looked.
- resizeEvent(event)[source]
Grow the plot font with the plot, once the dragging stops.
Each tab used to do this for itself, off the width of the whole window and with the same four magic numbers copied out five times. Off the canvas’s own width it is both in one place and correct: adding a control column beside the plot no longer changes the font on it.
- scientific_y(*axes)[source]
Label the y-axis as ‘4.3’ against a ‘1e5’, where that applies.
Photon rates run to a few million, and an axis labelled in full needs more room beside the plot than the plot can spare.
Silently skipped on a logarithmic axis:
ticklabel_formatonly understands the linear formatter and raises otherwise, which used to mean that new data arriving while the plot was on a log scale took the stream down with anAttributeError.
- style_axes()[source]
Ticks, spines and labels, identical on every plot.
Inward ticks on all four sides with a minor set between them: the convention the group’s published figures use, and the reason a plot lifted straight out of the application needs no editing.
- property theme
- twin = False
- x_label = ''
- y_label = ''
- daplis_rtp.gui.canvas.base.toolbar_min_width(toolbar, sample='(x, y) = (255.0, 2000.0)\n[0.957, 0.514, 0.514, 0.0857]')[source]
Width at which every toolbar button and the readout still fit.
A
QToolBarsqueezed below its contents hides them behind a ‘>>’ overflow button rather than forcing its parent wider - its ownminimumSizeHintis barely wider than that button - and the coordinate readout, being the widest item, is the first to go. It is also empty until the cursor reaches the axes, so nothing in the toolbar’s size hints reserves room for it while it is not needed.The width is measured rather than assumed: the readout is asked how wide it would be with a full reading in it, which picks up the application’s font and any padding the style adds, both of which differ between machines.