← 输入框|github.com|刷新
Skip to content

matplotlib bug in WinPython 2025-02 final Spyder Ipython console #1587

Closed

Description

@urima

Just 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'

Activity

  1. changed the title [-]matplotlib bug in WinPython 2025-02 final[/-] [+]matplotlib bug in WinPython 2025-02 final Spyder Ipython console[/+] on May 9, 2025
  2. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    161 print(
    162 "%pylab is deprecated, use %matplotlib inline and import the required libraries."
    163 )

  3. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    Does it work better with %matplotlib inline?

    You are on spyder6, maybe it's not supported anymore

  4. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    Image

  5. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    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.

    Image

  6. urima commented on May 9, 2025

    @urima
    Author

    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.

  7. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    smell like this: spyder-ide/spyder#22224

  8. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    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

    Name Version Description
    matplotlib 3.10.1
    matplotlib-inline 0.1.7
    spyder 6.0.5
    spyder-kernels 3.0.3
  9. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    there is a comment earlier in that thread that suggests to do

    import matplotlib_inline;
    matplotlib_inline.backend_inline.set_matplotlib_formats('png', 'jpeg');

  10. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    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

  11. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    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:

    Image

  12. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    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))
    
  13. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    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()
    

    Image

  14. stonebig commented on May 9, 2025

    @stonebig
    Contributor

    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');

  15. stonebig commented on May 9, 2025

    @stonebig
    Contributor
  16. stonebig commented on May 11, 2025

    @stonebig
    Contributor

    still not sure of the root cause... it was supposed to be fixed upstream.

  17. stonebig commented on May 11, 2025

    @stonebig
    Contributor

    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 ?)

  18. stonebig commented on May 17, 2025

    @stonebig
    Contributor

    ok, so going to the infringing bug line, i get:

    with

    Image

    this:
    formats: {'g', 'p', 'n'}

    meaning a 'png' string has been transformed into {'g', 'p', 'n'} instead of {'png'}

  19. stonebig commented on May 17, 2025

    @stonebig
    Contributor

    ha ha, if in the spyder default I replace PNG per SVG,

    Image

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

    Image

  20. stonebig commented on May 17, 2025

    @stonebig
    Contributor

    so there is in spyder.ini the line

    pylab/inline/figure_format = svg
    
  21. stonebig commented on May 17, 2025

    @stonebig
    Contributor

    ok if I do:

    %pylab inline
    
    

    I don't crash , but graphics don't show up right either

  22. stonebig commented on May 17, 2025

    @stonebig
    Contributor

    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

  23. urima commented on May 19, 2025

    @urima
    Author

    Yes! All the matplotlib issues is solved by:
    pip install --upgrade traitlets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions