-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
pyplot.subplots() is slow #7163
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
Comments
I think this is a duplicate of #6664 |
Probably related, but your issue doesn't seem to be specific to |
Yes, it's most likely the same cause. I didn't find it because Without knowing anything on the matplotlib internals, I'm still wondering why If this issue doesn't add additional information, it may be closed as duplicate. |
Yes, but
creates exactly one Axes instance, while
creates 40 Axes. |
No, with suitably different parameters, you get 40 |
import matplotlib.pylab as plt
ax1 = plt.subplot()
ax2 = plt.subplot()
print('same' if ax1 is ax2 else 'different') |
Of course that's the same; you're asking for the same subplot. import matplotlib.pylab as plt
ax1 = plt.subplot(40, 1, 1)
ax2 = plt.subplot(40, 1, 2)
print('same' if ax1 is ax2 else 'different') |
Yeah, that is strange:
|
Wait, I think I know what it is. I think What is missing is that the figure is never closed. In [3]: import matplotlib.pylab as plt
In [4]: def test():
....: for i in range(40):
....: plt.subplot(40, 1, i + 1)
....:
In [5]: %timeit plt.subplots(40)
1 loops, best of 3: 1.04 s per loop
In [6]: %%timeit plt.close('all')
...: plt.subplots(40)
...:
1 loops, best of 3: 1.03 s per loop
In [7]: plt.close('all')
In [8]: %timeit test()
The slowest run took 91.79 times longer than the fastest. This could mean that an intermediate result is being cached
1 loops, best of 3: 11.2 ms per loop
In [9]: %%timeit plt.close('all')
...: test()
...:
1 loops, best of 3: 1.01 s per loop That warning there is the key: 91.79 * 11.2ms ==1.028048s for the first run. So I'm going to close as a duplicate of #6664 then. |
Uh oh!
There was an error while loading. Please reload this page.
matplotlib 1.5.3, Python 2.7.3, Linux (Ubuntu 14.04 LTS), installed using pip
pyplot.subplots()
is significantly slower thanpyplot.subplot()
. This becomes significant when plotting a large number of subplots. For examplesubplots(40)
takes 2.3s whereas 40 calls tosubplot()
with differing parameters just take 25ms.Minimal example (using ipython):
sharex
,sharey
andsqueeze
(though I have not tested all possible parameters)reset_ticks
, which use up 75% of the time. See the runsnake screenshot below:It seems there is a lot of unneccesary(?) clearing happening. Would it be possible to speed this up?
The text was updated successfully, but these errors were encountered: