Skip to content

Allow custom matplotlib.Figure for plotting specs #189

@canismarko

Description

@canismarko

I want to plot scanspecs inside a pyqt widget. According to the matplotlib documentation I can do this by creating a canvas = FigureCanvas() and then creating axes on canvas.figure. However, scanspec.plot.plot_spec() creates its own figure each time I can't use this strategy.

My thought was to add an argument fig: Figure so I can do scanspec.plot.plot_spec(…, fig=canvas.figure). If not provided, plot_spec() creates a new figure as it does right now. If provided, figure.axes() will be called to create the new axes for plotting. I will have multiple such plots across several widgets so I need to tell plot_spec which figure it should plot to.

I had thought about provided ax: Axes as the argument. I'm not sure this will work, though, since plot_spec() needs to set a projection when creating an axes and it doesn't sound like you can change it afterwards: https://stackoverflow.com/a/34594651

I'm happy to submit this PR, just wanted to get some input before I started working on it.

Acceptance Criteria

  • A fig argument is available to scanspec.plot.plot_spec().
  • Provide a matplotlib figure results in plots being added to this figure.
  • The existing functionality is not altered if fig is not provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions