I am using seaborn style darkgrid. When I render the figure in jupyter it looks great. But when I save it with savefig(figure.jpeg, dpi=300). The colors of the grid are bad. Funny, when I upload the figure here, it looks good again. What is going on? And when I drop it in Chrome it looks bad. Is this a transparency issue? It is mainly the darker area in the background that is affected.
%pylab inline
import seaborn as sns
sns.set_style('darkgrid')
plot(something)
I would like to save the figure as it is displayed in the jupyter notebook so I can use it in other applications. What does the browser, what other image viewers don't have?
I tried formats jpeg and png. And saved the figure with transparency=True and transparency=False.
Related
In Jupyter, if the last statement in a cell returns a matplotlib.Figure, the figure is displayed.
One can perform a similar trick with custom classes by providing a _repr_png_ function in that class. However, matplotlib Figures do not provide this function. This makes me wonder. How does Jupyter "know" what to do with a matplotlib figure?
How does Jupyter "know" what to do with a matplotlib figure?
In the inline backend, this is achieved by registering a function to show changed figures (flush_figures) with the post_execute event in IPython, see configure_inline_support.
i am trying to generate a graph using matplotlib and save it to python-pptx . everything is working fine but the image resolution is low when imported to pptx.( i am just saving to memory using StringIO then using add_picture() in pptx to add image)
when i do :
some_image_in_memory = StringIO()
plt.savefig(some_image_in_memory)
it works fine but give low res image but when i do :
plt.savefig(some_image_in_memory, format='svg')
i get error:
cannot identify image file <StringIO.StringIO INstamce at ..>
is this even correct? svg should maintain resolution but i cant read this in pptx.
I got around this by setting dpi value to savefig():
ex
plt.savefig(some_image_stream_in_memory, dpi=1200)
Unfortunately, PowerPoint does not directly support the SVG format (I've heard it's a turf issue between MS and Adobe). I expect that explains the error you're getting when you save with format=svg.
Other folks seem to have good luck with the PNG format from matplotlib. I kind of suppose that's the default image format, but might be worth a check.
The other thing that occurs to me is I don't see anywhere you have specified the size of the graph to be saved from matplotlib. If it is getting saved as a small image and then getting scaled significantly larger when displaying it in PowerPoint, this will produce a "grainy" appearance.
I'm using Jupyter notebook with %matplotlib notebook in one of the first lines.
When making multiple plots, I have to physically press the 'stop interaction' button on each figure before running another plot, or else the newest plot will be overlaid onto the previous figure.
I think the problem is that I'm not specifying that a new figure needs to be made for each plot? But I'm stumped as to how best to do that!
DO I REALLY HAVE TO SAY PLT.FIGURE EVERY SINGLE TIME? THIS SEEMS UNLIKELY TO ME...?
Thanks in advance!
This is a bug with the notebook backend, but luckily the person who reported it also reported a workaround
Within the Notebook you will need to add the plt.ioff after you import pyplot.
Here is a snip from the top of a notebook, that makes it work for me. I was getting plots over written like you.
%matplotlib notebook # this is to allow the plotting in the notebook
import numpy as np
from scipy.linalg import hadamard
import matplotlib.pyplot as plt
plt.ioff() # this stops the graphs from overwriting each other
It's easy with pyplot but apparently pyplot shouldn't be used when embedding. I haven't been able to find any non-pyplot embedding examples where labels are used.
Maybe you found this page, too. Maybe this example helps. I have not tested it, thus I cannot say if it works.
Staying with the example from the matplotlib example, the labels in the subplot self.axes can be set using self.axes.set_xlabel(x Label") or self.axes.set_ylabel("y Label").
I am trying to use both bokeh and matplotlib in my IPython notebook... Neither work perfectly.
Attached is a screen shot of Bokeh. Matplotlib explanation is below.
Here are my system specs:
-Windows 7 with Vagrant
-Jupyter/IPython
BOKEH -- buttons are static images; there is no resizing, yet the graph is interactive
Should look like from this website: http://docs.bokeh.org/en/latest/docs/quickstart.html
MATPLOTLIB -- only static shots appear when it should be zoomable, etc (like bokeh)
1) read the documentation.
you would only change output_file() to a call to output_notebook() instead.
Which you did not seem to do above.
2) Why should it ? What di you do to make it zoomable ?
3) try not to post 2 unrelated question at the same time.
You appear to be using an older version of Bokeh. The issue with the CSS problems (button appearance) has been fixed for some time. As mentioned above, you will need to execute output_notebook() to load Bokeh for IPython notebook usage. For future reference, questions like this greatly benefit from providing as much information as possible (e.g., Bokeh and browser versions, platform information, etc.) Without that information it is impossible to diagnose problems with any certainty.