Skip to content

plot save and plot show #16909

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

Closed
big-vl opened this issue Mar 26, 2020 · 8 comments · Fixed by #17391
Closed

plot save and plot show #16909

big-vl opened this issue Mar 26, 2020 · 8 comments · Fixed by #17391

Comments

@big-vl
Copy link

big-vl commented Mar 26, 2020

/usr/local/lib/python3.8/dist-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 13 missing from current font.
  font.set_text(s, 0.0, flags=flags)
/usr/local/lib/python3.8/dist-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 13 missing from current font.
  font.set_text(s, 0, flags=flags)

plt.show()

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/backend_bases.py", line 2785, in _wait_cursor_for_draw_cm
    self.set_cursor(cursors.WAIT)
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/backends/_backend_tk.py", line 544, in set_cursor
    window.configure(cursor=cursord[cursor])
  File "/usr/lib/python3.8/tkinter/__init__.py", line 1640, in configure
    return self._configure('configure', cnf, kw)
  File "/usr/lib/python3.8/tkinter/__init__.py", line 1630, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name "."

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "sc.py", line 418, in <module>
    save_grf(path_db, grf_date, grf_bank, start_data, end_data)
  File "sc.py", line 298, in save_grf
    fig.savefig('png/'+str(name)+str(start_date)+'_'+str(end_date)+'.png')
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/figure.py", line 2203, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/backend_bases.py", line 2098, in print_figure
    result = print_method(
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/backends/backend_agg.py", line 514, in print_png
    FigureCanvasAgg.draw(self)
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/backends/backend_agg.py", line 390, in draw
    with RendererAgg.lock, \
  File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/backend_bases.py", line 2788, in _wait_cursor_for_draw_cm
    self.set_cursor(self._lastCursor)
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/backends/_backend_tk.py", line 544, in set_cursor
    window.configure(cursor=cursord[cursor])
  File "/usr/lib/python3.8/tkinter/__init__.py", line 1640, in configure
    return self._configure('configure', cnf, kw)
  File "/usr/lib/python3.8/tkinter/__init__.py", line 1630, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name "."

python v.: Python 3.8.2 (default, Feb 26 2020, 04:23:39)
matplotlib 3.2.1

dont save plot png.

@QuLogic
Copy link
Member

QuLogic commented Mar 26, 2020

Please provide code for reproduction, preferably without extraneous data or dependencies, like it asks for in the template.

@jklymak jklymak added the status: needs clarification Issues that need more information to resolve. label Mar 26, 2020
@big-vl
Copy link
Author

big-vl commented Mar 26, 2020

import matplotlib.pyplot as plt

def plot():
    fig, ax = plt.subplots()
    ax.plot([1, 2, 3, 4])
    ax.set(ylabel='some numbers')
    plt.show()
    fig.savefig('png/1.png')

for g in range(1,3):
    plot()

very strange behavior in python 3.5 there is no error, but in subsequent ones there is an error, there was an error in my code, first you need to save it to a file and then show here the error playback. after switching to python 3.8 he started showing it to me

@WeatherGod
Copy link
Member

WeatherGod commented Mar 26, 2020 via email

@big-vl
Copy link
Author

big-vl commented Mar 26, 2020

I wrote that you first need to save and then show why I thought that the error in the module and not everything worked for me in 3.5, thanks. maybe the developers will somehow check this problem :)

@anntzer
Copy link
Contributor

anntzer commented Mar 26, 2020

I also cannot repro as of e7fcb37 (just a bit before master, which suffers from a separate bug (#16926).

@HubChangWang
Copy link

Hi @big-vl ,have this prob solved? I encounter the same questions. when I save it to .svg format, this issue do not occur, however, when saving as png format, the program seems stuck at this save process. when I close the windows, it also gives me " invalid command name ."

@QuLogic
Copy link
Member

QuLogic commented May 20, 2020

This should be fixed by #17391.

@QuLogic QuLogic added status: confirmed bug and removed status: needs clarification Issues that need more information to resolve. labels May 20, 2020
@QuLogic QuLogic added this to the v3.2.2 milestone May 20, 2020
@andrekorol
Copy link

andrekorol commented May 21, 2020

I just ran over this bug, and I am glad this is already fixed and pushed into the next release. Until v3.2.2, I'll keep saving the figure before showing it.

The only problem is that depending on the size of the figure saving can take some time, that's why I intended to save only after showing. Users might notice this delay.

Is there any way to asynchronously save a figure other than the one described on https://gist.github.com/astrofrog/1453933?

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

Successfully merging a pull request may close this issue.

7 participants