How to autoscale an animation?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to autoscale an animation?

David Aldrich

Hi

 

I am having difficulty autoscaling a subplot in an animation.  A snippet of my code is:

 

fig, axarr = plt.subplots(nrows=2, ncols=5, figsize=(12, 6))

sc_dl_layer1 = axarr[0,4].scatter(x_data, y_data, c='r', s=4)

 

def updatePlots(i):

               <snip>

               sc_dl_layer1.set_offsets(np.c_[i_data_layer_1, q_data_layer_1])

sc_dl_layer1.autoscale()

 

ani = matplotlib.animation.FuncAnimation(fig, updatePlots, frames=None, interval=200, repeat=True)

plt.show()

 

This code returns:

 

  sc_dl_layer1.autoscale()

  File "C:\Program Files (x86)\Python36-32\lib\site-packages\matplotlib\cm.py", line 334, in autoscale

    raise TypeError('You must first set_array for mappable')

TypeError: You must first set_array for mappable

 

How can I fix this please?

 

Best regards

 

David

 


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: How to autoscale an animation?

tcaswell

You are calling auto scale on the scatter artist which is trying to scale the data for color mapping the scatter.  You want to be calling auto scale on the Axes (in this case I think axarr[0, 4]).

Tom


On Thu, Jul 13, 2017, 12:40 David Aldrich <[hidden email]> wrote:

Hi

 

I am having difficulty autoscaling a subplot in an animation.  A snippet of my code is:

 

fig, axarr = plt.subplots(nrows=2, ncols=5, figsize=(12, 6))

sc_dl_layer1 = axarr[0,4].scatter(x_data, y_data, c='r', s=4)

 

def updatePlots(i):

               <snip>

               sc_dl_layer1.set_offsets(np.c_[i_data_layer_1, q_data_layer_1])

sc_dl_layer1.autoscale()

 

ani = matplotlib.animation.FuncAnimation(fig, updatePlots, frames=None, interval=200, repeat=True)

plt.show()

 

This code returns:

 

  sc_dl_layer1.autoscale()

  File "C:\Program Files (x86)\Python36-32\lib\site-packages\matplotlib\cm.py", line 334, in autoscale

    raise TypeError('You must first set_array for mappable')

TypeError: You must first set_array for mappable

 

How can I fix this please?

 

Best regards

 

David

 

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users