Boris Barbour wrote:
Eric and John,

Thanks for the information. You are right that this probably would have been a premature optimisation, even if it weren't rendered useless by matplotlib using doubles internally (which I hadn't realised). The thought just occurred to me as I was writing the data-scaling part of my script.

The script is intended to be somewhat interactive. Initial tests suggest that plotting or updating several subplots from memory does take a quite noticeable time (e.g. 1.2 -- 1.5 seconds for 3 subplots of 10000 points) that will probably become annoying in routine use. As you indicated, basically all that time is spent within matplotlib. I'm just using standard default calls:

for i in subplot
    subplot     
    plot
    xlabel
    ylabel
    title

Each of these calls seems to take roughly the same time (60--100ms). If

It sounds like you have interactive mode on, in which case each pylab function redraws the figure. The solution is to use the object-oriented interface for almost everything. See the attached example.

anybody has pointers on speeding things up significantly, I'm all ears. (Predefining data limits? Using lower-level commands? Use of a non-default backend?)

If the suggestion above is not enough, we will need to know more about what your script looks like, the environment in which it is running (e.g., ipython? embedded in wx? straight command line? what operating system? what backend?), your constraints, and what you are trying to accomplish. The best thing would be if you could post a very short self-contained script, typically using fake random data, that shows your present approach and that illustrates the speed problem; then we can try to figure out what the bottlenecks are, and whether there are simple ways to speed up the script or to modify mpl for better speed.

Eric

import time
import numpy as np
import matplotlib.pyplot as plt

npts = 10000
xx = np.arange(npts)

plt.ion()

t0 = time.time()
fig1 = plt.figure()
ax = fig1.add_subplot(1,1,1)
# Try again, commenting out the following three lines;
# you will see no significant difference in the plotting time.
ax.set_title('A title')
ax.set_xlabel('This is X')
ax.set_ylabel('This is Y')

lines = ax.plot(xx, np.random.rand(npts))
plt.draw()
t1 = time.time()

print t1-t0

for ii in range(10):
    t0 = time.time()
    lines[0].set_data(xx, np.random.rand(npts))
    plt.draw()
    t1 = time.time()

    print t1-t0


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to