Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jpg not supported by matplotlib backend #8052

Closed
jankatins opened this issue Mar 14, 2015 · 11 comments
Closed

jpg not supported by matplotlib backend #8052

jankatins opened this issue Mar 14, 2015 · 11 comments
Milestone

Comments

@jankatins
Copy link
Contributor

Just got an error after enabling the jpg matplotlib format:

%matplotlib inline
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('png', 'jpg')
ValueError                                Traceback (most recent call last)
C:\portabel\miniconda\envs\ipython\lib\site-packages\IPython\core\formatters.pyc in __call__(self, obj)
    333                 pass
    334             else:
--> 335                 return printer(obj)
    336             # Finally look for special method names
    337             method = _safe_get_formatter_method(obj, self.print_method)

C:\portabel\miniconda\envs\ipython\lib\site-packages\IPython\core\pylabtools.pyc in <lambda>(fig)
    209         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
    210     if 'jpg' in formats or 'jpeg' in formats:
--> 211         jpg_formatter.for_type(Figure, lambda fig: print_figure(fig, 'jpg', **kwargs))
    212     if 'svg' in formats:
    213         svg_formatter.for_type(Figure, lambda fig: print_figure(fig, 'svg', **kwargs))

C:\portabel\miniconda\envs\ipython\lib\site-packages\IPython\core\pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
    115     
    116     bytes_io = BytesIO()
--> 117     fig.canvas.print_figure(bytes_io, **kw)
    118     data = bytes_io.getvalue()
    119     if fmt == 'svg':

C:\portabel\miniconda\envs\ipython\lib\site-packages\matplotlib\backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2117 
   2118         # get canvas object and print method for format
-> 2119         canvas = self._get_output_canvas(format)
   2120         print_method = getattr(canvas, 'print_%s' % format)
   2121 

C:\portabel\miniconda\envs\ipython\lib\site-packages\matplotlib\backend_bases.pyc in _get_output_canvas(self, format)
   2059         raise ValueError('Format "%s" is not supported.\n'
   2060                          'Supported formats: '
-> 2061                          '%s.' % (format, ', '.join(formats)))
   2062 
   2063     def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',

ValueError: Format "jpg" is not supported.
Supported formats: eps, pdf, pgf, png, ps, raw, rgba, svg, svgz.

IPython.core.pylabtools has this here:

    supported = {'png', 'png2x', 'retina', 'jpg', 'jpeg', 'svg', 'pdf'}

So I suspect that something is wrong here...

This is IPython 3.0, matplotlib 1.4.3 (both from condas repository), Win7

@minrk
Copy link
Member

minrk commented Mar 14, 2015

I think matplotlib requires PIL for jpg export to work:

conda install pillow

@takluyver takluyver added this to the no action milestone Mar 14, 2015
@jankatins
Copy link
Contributor Author

Shouldn't this then be:

supported = {'png', 'png2x', 'retina', 'svg', 'pdf'}
try:
    from PIL import Image
    supported = supported.union({'jpg', 'jpeg'})
except:
    pass 

@Carreau
Copy link
Member

Carreau commented Mar 14, 2015

Probably not, cause this would import PIL which is relatively heavy, even if people don't use it.

@minrk
Copy link
Member

minrk commented Mar 14, 2015

And the export formats only requires PIL for certain backends (Agg/inline, but not GTK or OS X).

@Carreau
Copy link
Member

Carreau commented Jul 19, 2017

Hi,

This issue has been quiet for almost 2 years, and I don't think there is anything we can do. It has been marked as no-action, and I'm going to close it to attempt to reduce the number of opened issue. Feel free to reopen if needed.

Thanks.

@Carreau Carreau closed this as completed Jul 19, 2017
@imahgrefteh
Copy link

pip3 install pillow got it to work for me

@matrix-1992
Copy link

pip install pillow also can't solve the problem in my computer.....

@jash101
Copy link

jash101 commented Jan 23, 2019

pip install pillow also can't solve the problem in my computer.....

Try uninstalling pillow first and then install it back. Worked for me.
sudo pip3 uninstall pillow
sudo pip3 install pillow

@berkayyildirim
Copy link

berkayyildirim commented Jan 15, 2020

I had encountered the same problem and solutions above had not been able to solve my issue. After that, I just tried plt.savefig("images/pie.png") by replacing .jpg with .png in .py file as well as in my .html file. Finally, pie.png was automatically added to my folders and my problem was solved.

@tacaswell
Copy link
Contributor

This is due to a bug in Matplotlib (see matplotlib/matplotlib#16083) in how we were checking the version of pillow which was removed in pillow 7.0. This has been fixed on the relevant branches upstream and bug-fix releases should go out soon. For now, downgrade pillow.

@pablobots
Copy link

pip install "pillow<7" got it to work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants