matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.59k stars 225 forks source link

button for canvas toolbar which enables creating a pdf of the figure #443

Open jkochNU opened 2 years ago

jkochNU commented 2 years ago

As discussed with @ianhi, this is an attempt to (partially) address #138. This would add an additional button to the toolbar associated with a figure.canvas. Once clicked, a pdf is generated with savefig and then handed over to the frontend inside a new tab.

image

github-actions[bot] commented 2 years ago

Binder :point_left: Launch a binder notebook on branch _jkochNU/ipympl/toolbar_pdfbutton

ianhi commented 2 years ago

@jkochNU heads up that the pre-commit bot push a commit with styling changes. You can either git pull or on your next push do git push -fto override that commit (but then it will happen again to auto style things). I'd also recommend installing it locally with pre-commit install

jkochNU commented 2 years ago

That said I don't think that the correct solution is to limit ourselves to pdfs here. Instead we could have the button mean "Save according to rcparams" and a second button (probably with a different icon) that would do the current behavior of downloading.

@ianhi Before I make changes in that direction: in my mind, a more flexible solution should do the following: upon clicking the new button, open a native file dialog box. There, the export file type could default to the one in rcParams, but the file type dropdown should allow for a variety of choices supported by savefig. I've looked into this a bit more, and it is less clear to me now that this is as simple as I was hoping for.

Regarding your suggested solution: we should keep in mind that rcParams already defaults to png format. So unless the user makes an explicit change, displaying a separate button saving to the rcParams format will typically just result in yet another button saving to png. We could make the presence of the additional button depend on whether the rcParams format differs from png. The button would remain missing, though, if the rcParams format was changed midway...