Closed
Description
I'm building a napari plugin that computes some derived data and plots that in a pane (so we're not directly hooking the plot up to the layer content). I am trying to use the BaseNapariMPLWidget
to have a single plot with toolbar, rather than just docking the figure canvas. I also want to be able to save the figure, however the none of the the ticks, ticklabels, or axis labels appear in a png of the figure.
Minimal example
import matplotlib.pyplot as plt
import napari
import numpy as np
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from napari_matplotlib.base import BaseNapariMPLWidget
if __name__ == '__main__':
viewer = napari.Viewer()
complete_widget = BaseNapariMPLWidget(viewer)
complete_widget.add_single_axes()
complete_widget.axes.plot(np.arange(10), np.sin(np.arange(10)))
viewer.window.add_dock_widget(complete_widget, name="Complete")
figure = plt.figure()
ax = figure.gca()
ax.plot(np.arange(10), np.sin(np.arange(10)))
canvas_widget = FigureCanvasQTAgg(figure)
viewer.window.add_dock_widget(canvas_widget, name="Canvas")
complete_widget.figure.savefig("test_napari_mpl.png", dpi=300)
figure.savefig("test_canvas.png", dpi=300)
napari.run()
Happy to submit a PR with a bit of guidance as where to start. Is this in the choice of canvas?
Metadata
Metadata
Assignees
Labels
No labels