SourceForge logo
SourceForge logo
Menu

matplotlib-devel

From: Mauricio C. <moc...@gm...> - 2014年02月01日 15:45:02
Hi there,
I have the following simple code to plot a (static) fill_between region in
a given plot.
import numpy as np
import matplotlib. pyplot as plt
plt.figure()
ax=plt.axes()
ax.set_xlim([0,10000])
x = np.linspace(6000.,7000.)
y = np.ones(np.shape(x))
plt.fill_between(x,y)
I would like now to animate this band (which is a PolyCollection object,
and not a Line2D one) so that it moves smoothly to the right up together
with being stretched, that is, to the new x positions: .7200, 8400. I saw
several animations in the matplotlib homepage, but they only looped over
line or image objects, not polycollection ones, such as fill_between... Is
this possible?
In stackoverflow there is this link:
http://stackoverflow.com/questions/16120801/matplotlib-animate-fill-between-shape,
which might solve this question but I was not able to understand it fully
in order to have a simple minmal working example. If that is the right
direction, I would appreciate immensely if someone could provide such an
example!
Thanks in advance
-- 
#######################################
Prof. Mauricio Ortiz Calvao
Federal University of Rio de Janeiro
Institute of Physics, P O Box 68528
CEP 21941-972 Rio de Janeiro, RJ
Brazil
Email: or...@if...
Phone: (55)(21)25627483
Homepage: http://www.if.ufrj.br/~orca
#######################################
From: Jacob V. <ja...@cs...> - 2014年02月02日 16:38:33
Hi Mauricio,
Patch objects are a bit more difficult to work with than line objects,
because unlike line objects are a step removed from the input data supplied
by the user. There is an example similar to what you want to do here:
http://matplotlib.org/examples/animation/histogram.html
Basically, you need to modify the vertices of the path at each frame. It
might look something like this:
from matplotlib import animation
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_xlim([0,10000])
x = np.linspace(6000.,7000., 5)
y = np.ones_like(x)
collection = plt.fill_between(x, y)
def animate(i):
 path = collection.get_paths()[0]
 path.vertices[:, 1] *= 0.9
animation.FuncAnimation(fig, animate,
 frames=25, interval=30)
Take a look at path.vertices to see how they're laid out.
Hope that helps,
 Jake
On Sat, Feb 1, 2014 at 7:44 AM, Mauricio Calvao <moc...@gm...> wrote:
> Hi there,
>
> I have the following simple code to plot a (static) fill_between region
> in a given plot.
>
>
> import numpy as np
> import matplotlib. pyplot as plt
>
> plt.figure()
> ax=plt.axes()
> ax.set_xlim([0,10000])
>
> x = np.linspace(6000.,7000.)
> y = np.ones(np.shape(x))
>
> plt.fill_between(x,y)
>
>
> I would like now to animate this band (which is a PolyCollection object,
> and not a Line2D one) so that it moves smoothly to the right up together
> with being stretched, that is, to the new x positions: .7200, 8400. I saw
> several animations in the matplotlib homepage, but they only looped over
> line or image objects, not polycollection ones, such as fill_between... Is
> this possible?
>
> In stackoverflow there is this link:
> http://stackoverflow.com/questions/16120801/matplotlib-animate-fill-between-shape,
> which might solve this question but I was not able to understand it fully
> in order to have a simple minmal working example. If that is the right
> direction, I would appreciate immensely if someone could provide such an
> example!
>
> Thanks in advance
>
> --
> #######################################
> Prof. Mauricio Ortiz Calvao
> Federal University of Rio de Janeiro
> Institute of Physics, P O Box 68528
> CEP 21941-972 Rio de Janeiro, RJ
> Brazil
>
> Email: or...@if...
> Phone: (55)(21)25627483
> Homepage: http://www.if.ufrj.br/~orca
> #######################################
>
>
> ------------------------------------------------------------------------------
> WatchGuard Dimension instantly turns raw network data into actionable
> security intelligence. It gives you real-time visual feedback on key
> security issues and trends. Skip the complicated setup - simply import
> a virtual appliance and go from zero to informed in seconds.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
> _______________________________________________
> Matplotlib-devel mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>
>
From: Mauricio C. <moc...@gm...> - 2014年02月02日 16:28:57
Thank you Jake.
I will take a look at this example with care.
Cheers!
On Sun, Feb 2, 2014 at 2:10 PM, Jacob Vanderplas
<ja...@cs...>wrote:
> Hi Mauricio,
> Patch objects are a bit more difficult to work with than line objects,
> because unlike line objects are a step removed from the input data supplied
> by the user. There is an example similar to what you want to do here:
> http://matplotlib.org/examples/animation/histogram.html
>
> Basically, you need to modify the vertices of the path at each frame. It
> might look something like this:
>
> from matplotlib import animation
> import numpy as np
> import matplotlib.pyplot as plt
>
> fig, ax = plt.subplots()
> ax.set_xlim([0,10000])
>
> x = np.linspace(6000.,7000., 5)
> y = np.ones_like(x)
>
> collection = plt.fill_between(x, y)
>
> def animate(i):
> path = collection.get_paths()[0]
> path.vertices[:, 1] *= 0.9
>
> animation.FuncAnimation(fig, animate,
> frames=25, interval=30)
>
> Take a look at path.vertices to see how they're laid out.
> Hope that helps,
> Jake
>
>
> On Sat, Feb 1, 2014 at 7:44 AM, Mauricio Calvao <moc...@gm...>wrote:
>
>> Hi there,
>>
>> I have the following simple code to plot a (static) fill_between region
>> in a given plot.
>>
>>
>> import numpy as np
>> import matplotlib. pyplot as plt
>>
>> plt.figure()
>> ax=plt.axes()
>> ax.set_xlim([0,10000])
>>
>> x = np.linspace(6000.,7000.)
>> y = np.ones(np.shape(x))
>>
>> plt.fill_between(x,y)
>>
>>
>> I would like now to animate this band (which is a PolyCollection object,
>> and not a Line2D one) so that it moves smoothly to the right up together
>> with being stretched, that is, to the new x positions: .7200, 8400. I saw
>> several animations in the matplotlib homepage, but they only looped over
>> line or image objects, not polycollection ones, such as fill_between... Is
>> this possible?
>>
>> In stackoverflow there is this link:
>> http://stackoverflow.com/questions/16120801/matplotlib-animate-fill-between-shape,
>> which might solve this question but I was not able to understand it fully
>> in order to have a simple minmal working example. If that is the right
>> direction, I would appreciate immensely if someone could provide such an
>> example!
>>
>> Thanks in advance
>>
>> --
>> #######################################
>> Prof. Mauricio Ortiz Calvao
>> Federal University of Rio de Janeiro
>> Institute of Physics, P O Box 68528
>> CEP 21941-972 Rio de Janeiro, RJ
>> Brazil
>>
>> Email: or...@if...
>> Phone: (55)(21)25627483
>> Homepage: http://www.if.ufrj.br/~orca
>> #######################################
>>
>>
>> ------------------------------------------------------------------------------
>> WatchGuard Dimension instantly turns raw network data into actionable
>> security intelligence. It gives you real-time visual feedback on key
>> security issues and trends. Skip the complicated setup - simply import
>> a virtual appliance and go from zero to informed in seconds.
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Matplotlib-devel mailing list
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>>
>>
>
-- 
#######################################
Prof. Mauricio Ortiz Calvao
Federal University of Rio de Janeiro
Institute of Physics, P O Box 68528
CEP 21941-972 Rio de Janeiro, RJ
Brazil
Email: or...@if...
Phone: (55)(21)25627483
Homepage: http://www.if.ufrj.br/~orca
#######################################
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /