Save digit to .pdf after displaying in python notebook

A similar question has been asked here and here on the Stack, but I'm not satisfied that it still doesn't solve my problem.

I have a function that does some calculations and displays a shape (without returning a shape object). Out of personal preference (and to keep track of how my plots looked, without saving each one), I am using %matplotlib inline

in IPython. Now, after I generated some plots, I decided to save one of them (say the second of 3 displayed in the notebook), which works fine by right clicking and selecting "Save As ..." but only as .png.

Is there a way to save it as .pdf without changing the function to return the curly object? (I know it's not difficult, but for most of my cases, it just isn't necessary, since it's 1 out of, say, 20 digits to be saved at the end).

I figured out that the backend changes after %matplotlib inline

, which is (I think) why I can't save the numbers as .pdf. The workaround seems to be using %config InlineBackend.close_figures = False

and using plt.savefig(...)

(answer from here ). But this way I could only keep the last digit and close the digits manually each time.

If my problem comes from poor workflow / programming style, I would happily accept suggestions on how to do it better. If you need a sample code, I can provide it. I use:

ipython (2.1.0)
matplotlib (1.4.1) (with Qt4Agg backend if not inline)
Python 2.7.6
MacOSX 10.9.4

      

+3


source to share


1 answer


Sending as response:

You cannot save the PDF directly from your browser, because the browser and the JS code do not know that the PNG image it displays is associated with a specific matplotlib drawing - indeed, it does not know about matplotlib at all.All that is handled by the Python kernel process with your code.



However, you can configure IPython to display numbers in SVG format as described in the docs . It also has a PDF option, although I forget what it does.

+2


source







All Articles