GeezerVison is showing github.com — matplotlib bug in WinPython 2025-02 final Spyder Ipython console · Issue #1587 · winpython/winpython
matplotlib bug in WinPython 2025-02 final Spyder Ipython console #1587DescriptionJust type "%pylab" in ipython console or click the "Inline" on the statusbar.
Here is what I got:
Python 3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 8.34.0 -- An enhanced Interactive Python. Type '?' for help.
%pylab
ValueError Traceback (most recent call last)
Cell In[1], line 1
----> 1 get_ipython().run_line_magic('pylab', '')
File C:\winPython\WPy64-312100\python\Lib\site-packages\IPython\core\interactiveshell.py:2482, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
2480 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2481 with self.builtin_trap:
-> 2482 result = fn(*args, **kwargs)
2484 # The code below prevents the output from being displayed
2485 # when using magics with decorator @output_can_be_silenced
2486 # when the last Python token in the expression is a ';'.
2487 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):
File C:\winPython\WPy64-312100\python\Lib\site-packages\IPython\core\magics\pylab.py:159, in PylabMagics.pylab(self, line)
155 else:
156 # invert no-import flag
157 import_all = not args.no_import_all
--> 159 gui, backend, clobbered = self.shell.enable_pylab(args.gui, import_all=import_all)
160 self._show_matplotlib_backend(args.gui, backend)
161 print(
162 "%pylab is deprecated, use %matplotlib inline and import the required libraries."
163 )
File C:\winPython\WPy64-312100\python\Lib\site-packages\IPython\core\interactiveshell.py:3721, in InteractiveShell.enable_pylab(self, gui, import_all, welcome_message)
3694 """Activate pylab support at runtime.
3695
3696 This turns on support for matplotlib, preloads into the interactive
(...)
3717 This argument is ignored, no welcome message will be displayed.
3718 """
3719 from IPython.core.pylabtools import import_pylab
-> 3721 gui, backend = self.enable_matplotlib(gui)
3723 # We want to prevent the loading of pylab to pollute the user's
3724 # namespace as shown by the %who* magics, so we execute the activation
3725 # code in an empty namespace, and we update both user_ns and
3726 # user_ns_hidden with this information.
3727 ns = {}
File C:\winPython\WPy64-312100\python\Lib\site-packages\IPython\core\interactiveshell.py:3683, in InteractiveShell.enable_matplotlib(self, gui)
3679 pt.activate_matplotlib(backend)
3681 from matplotlib_inline.backend_inline import configure_inline_support
-> 3683 configure_inline_support(self, backend)
3685 # Now we must activate the gui pylab wants to use, and fix %run to take
3686 # plot updates into account
3687 self.enable_gui(gui)
File C:\winPython\WPy64-312100\python\Lib\site-packages\matplotlib_inline\backend_inline.py:205, in configure_inline_support(shell, backend)
202 cur_backend = getattr(configure_inline_support, "current_backend", "unset")
203 if new_backend_name != cur_backend:
204 # Setup the default figure format
--> 205 select_figure_formats(shell, cfg.figure_formats, **cfg.print_figure_kwargs)
206 configure_inline_support.current_backend = new_backend_name
File C:\winPython\WPy64-312100\python\Lib\site-packages\IPython\core\pylabtools.py:297, in select_figure_formats(shell, formats, **kwargs)
295 bs = "%s" % ','.join([repr(f) for f in bad])
296 gs = "%s" % ','.join([repr(f) for f in supported])
--> 297 raise ValueError("supported formats are: %s not %s" % (gs, bs))
299 if "png" in formats:
300 png_formatter.for_type(
301 Figure, partial(print_figure, fmt="png", base64=True, **kwargs)
302 )
ValueError: supported formats are: 'jpg','jpeg','png2x','png','retina','svg','pdf' not 'p','g','n' Activitychanged the title [-]matplotlib bug in WinPython 2025-02 final[/-] [+]matplotlib bug in WinPython 2025-02 final Spyder Ipython console[/+] on May 9, 2025stonebig commented on May 9, 2025 161 print(
162 "%pylab is deprecated, use %matplotlib inline and import the required libraries."
163 ) stonebig commented on May 9, 2025 Does it work better with %matplotlib inline?
You are on spyder6, maybe it's not supported anymore stonebig commented on May 9, 2025 stonebig commented on May 9, 2025 stonebig commented on May 9, 2025 the ipython console of spyder is a qtconsole, and so to get a closer experience to web-ipython experience some may expect, they would need to use spyder-notebook
It's a very complex matter, that is maybe improvable if Spyder moves to Qt6... but at that time it will be even bigger weight (50 Mo ?)
The good News for Spyder/Qt community, is that Qt Company is going well.

urima commented on May 9, 2025 Thank you for the detailed answer.
I'm using win 10 and I test it on 2 computers.
I switch to graphics qt in the spyder setting.
then I type in the ipython console:
from pylab import *
plot(range(100))
The figure window pops up but there is no plot and the window not responses.
when I do the same on the spyder standalone 6.0.5 installer (https://www.spyder-ide.org/) everything works fine. stonebig commented on May 9, 2025 stonebig commented on May 9, 2025 well, the story of wron versions didn't end there, see last commet here spyder-ide/spyder#22420 (comment)
we are apparently up-to-date, so the suggestion of this last comment (not a package version) looks right.
when you switched the default backend maybe then close and restart spyder
stonebig commented on May 9, 2025 there is a comment earlier in that thread that suggests to do
import matplotlib_inline;
matplotlib_inline.backend_inline.set_matplotlib_formats('png', 'jpeg'); stonebig commented on May 9, 2025 As you error message as apparently transformed a 'png' into a 'p', 'n', 'g' ... I would presume somewhere a 'png' is taken instead of a list like ("png", "jpeg")
... like an error of "default=", when nothing is provided, somewhere in one's code stonebig commented on May 9, 2025 soooo, following this advice from spyder-ide/spyder#22420 (comment)
shall save your day
import matplotlib_inline; matplotlib_inline.backend_inline.set_matplotlib_formats('png', 'jpeg');
from pylab import *
plot(range(100))
to get:

stonebig commented on May 9, 2025 anyway Spyder team is discouraging you to use pylab...
so the simple trick, to use inline code, seems the only one that will work
import matplotlib_inline; matplotlib_inline.backend_inline.set_matplotlib_formats('png', 'jpeg');
from pylab import *
plot(range(100))
stonebig commented on May 9, 2025 it's really a no brainer solution:
default run doesn't fail
running it in external console produces the Qt drawing
import matplotlib_inline; matplotlib_inline.backend_inline.set_matplotlib_formats('png', 'jpeg');
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(-10, 10, 100)
sig = 1 / (1 + np.exp(-t))
fig, ax = plt.subplots()
ax.axhline(y=0, color="black", linestyle="--")
ax.axhline(y=0.5, color="black", linestyle=":")
ax.axhline(y=1.0, color="black", linestyle="--")
ax.axvline(color="grey")
ax.axline((0, 0.5), slope=0.25, color="black", linestyle=(0, (5, 5)))
ax.plot(t, sig, linewidth=2, label=r"$\sigma(t) = \frac{1}{1 + e^{-t}}$")
ax.set(xlim=(-10, 10), xlabel="t")
ax.legend(fontsize=14)
plt.show()

stonebig commented on May 9, 2025 Spyder-5 was going to held WinPython back on some dependancies, so there was no question to move to Spyder-6 this round.
Spyder-6 is a bit founded per some foundations, so anyway, the only way was forward.
if the auto-installer of Spyder works, I presume there shall be a fix in an anaconda version of one of the packages involved
import matplotlib_inline; matplotlib_inline.backend_inline.set_matplotlib_formats('png', 'jpeg');
stonebig commented on May 9, 2025 stonebig commented on May 11, 2025 still not sure of the root cause... it was supposed to be fixed upstream. stonebig commented on May 11, 2025 the suggestion works, while no explanation why standalone spyder did fix it
next matplotlib and next spyder on pypi may have a fixed included
maybe it's default on .spyder ( a spyder reset ?) stonebig commented on May 17, 2025 ok, so going to the infringing bug line, i get:
with

this:
formats: {'g', 'p', 'n'}
meaning a 'png' string has been transformed into {'g', 'p', 'n'} instead of {'png'} stonebig commented on May 17, 2025 ha ha, if in the spyder default I replace PNG per SVG,

I get a {'g', 'v', 's'}

stonebig commented on May 17, 2025 so there is in spyder.ini the line
pylab/inline/figure_format = svg
stonebig commented on May 17, 2025 ok if I do:
I don't crash , but graphics don't show up right either stonebig commented on May 17, 2025 solved:
- you have to update the packege traitlets to traitlets-5.14.3
see: ipython/traitlets#903
please @urima , confirm it does resolve your issue urima commented on May 19, 2025 Yes! All the matplotlib issues is solved by:
pip install --upgrade traitlets Reacted by urima Reacted by stonebig
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|