Skip to content

Saving figure has no ticks or axis labels #231

Closed
@Goobley

Description

@Goobley

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

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