Skip to content

[Feature]: Give Waveform.plot() the same themes as the result plots #33

Description

@fedonman

Feature Summary

Waveform.plot() and IQWaveform.plot() set no colours, no grid and no theme. Once result plotting has a theme, route waveform plotting through the same one.

Motivation / Use Case

Plotting a pi pulse and then the Rabi sweep it produced should not look like two different libraries drew them. Unifying is much cheaper while there are two plotting methods than after a result-plotting API has shipped its own conventions.

There is a concrete problem in notebooks too. _repr_html_ returns SVG with matplotlib's stock white background and no dark-mode handling, so a bare waveform in a dark-themed notebook renders as a white rectangle. The documentation site solved this for its own figures by shipping a light and a dark variant of each, and none of that is reachable from the package.

Follows #32, whose theme and style types this would use.

Proposed Solution

pulse.plot(style=Style(theme=dark))

Take the figure size from the style instead of the two hardcoded literals, and give the envelope the theme's first series colour, with I and Q taking the first two the way the documentation figures already do. Keep ax and axes and keep returning them, since composing into a caller's grid is the existing contract and a good one.

While the file is open: _waveform_svg picks its figure up with plt.gcf(), and its docstring documents that the plotting callable has to leave the figure as pyplot's current one. Passing the figure in instead removes an ordering contract that only holds by convention, and it is what a non-pyplot renderer would need.

One thing to settle: whether _repr_html_ keeps emitting a single light SVG, or emits both and picks with a CSS media query the way the docs pages do. The second renders correctly in either notebook theme at twice the cost, which for one waveform is small.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    waveformsTouches waveforms and the waveform library

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions