[Matplotlib-users] Plot

Bruno Pagani bruno.pagani at astrophysics.eu
Wed Aug 14 10:00:06 EDT 2019


I guess adding a call to plt.figure() before each new figure should do
it. Eventually plt.close() just before that if you want to close figures
instead of keeping them open (but then you might also just be able to
clear the current one instead of closing/opening).

Le 14/08/2019 à 06:47, Partha Sinha a écrit :
> I got the solution as suggested by scott. 
> My new problem is:
> Lets say I will generate lets  two pairs of 10 random numbers, say x
> and y.
> When first pair of x and y is generated, it will be plotted. Again
> when second set of number is generated, it will appear on the same
> graph and not on 2nd graph.
> This will continue till 10th pair.
> How to do this?
> Regards
> Parth
>
>
> On 3 Aug 2019 1:17 pm, "Scott Lasley" <selasley at icloud.com
> <mailto:selasley at icloud.com>> wrote:
>
>     This should do what you want.   It works in a jupyter notebook but
>     not in jupyterlab.  It also works as a standalone python script if
>     you comment out the %matplotlib notebook line.
>
>     Best regards,
>     Scott
>
>
>
>     # based on
>     https://matplotlib.org/gallery/animation/animate_decay.html#sphx-glr-gallery-animation-animate-decay-py
>     <https://matplotlib.org/gallery/animation/animate_decay.html#sphx-glr-gallery-animation-animate-decay-py>
>     # but uses a zip iterator for the frames variable in FuncAnimation
>     instead of the data_gen generator function
>     # used in the example
>
>     # comment out this line if you are not running this in a jupyter
>     notebook
>     %matplotlib notebook
>     # %matplotlib nbagg
>
>     import numpy as np
>     from matplotlib import pyplot as plt
>     from matplotlib.animation import FuncAnimation
>
>
>     def init_plot():
>         # if you know the data ranges you can set fixed
>         # xlim and ylim limits here, otherwise uncomment
>         # the ax.relim and ax.autoscale_view calls in
>         # draw_pts to rescale the axes based on the
>         # last data point plotted
>         ax.set(xlim=[0, 11], ylim=[0, 120])
>         return []
>
>
>     def update_pts(data):
>         x.append(data[0])
>         y.append(data[1])
>         pts.set_data(x, y)
>     #     ax.relim()
>     #     ax.autoscale_view(scaley=True)
>         return [pts]
>
>
>     # data to plot.  replace with your data values
>     xvals = np.arange(1, 11)
>     yvals = np.array([1, 4, 9, 16, 25, 36, 49, 64, 81, 100])
>
>     # zip xvals[1:] and yvals[1:] since we are plotting
>     # xvals[0], yvals[0] at time 0 after we create the figure
>     xy_points = zip(xvals[1:], yvals[1:])
>
>     # create x and y lists containing the first point to be plotted.
>     # update_pts will append the next x and y values from the iterator
>     xy_points
>     # to x and y every 5000ms and update the pts being plotted
>     x = [xvals[0]]
>     y = [yvals[0]]
>
>     # create a figure and plot the first x, y point at time 0
>     fig, ax = plt.subplots()
>     pts = ax.plot(x, y, 'o')[0]
>
>     # loop through the remaining points and update the plot every
>     # 5000ms
>     anim = FuncAnimation(fig=fig,
>                         func=update_pts,
>                         frames=xy_points,
>                         init_func=init_plot,
>                         interval=5000,
>                         blit=False,
>                         repeat=False)
>
>     plt.show()
>
>
>
>     > On Aug 3, 2019, at 1:04 AM, Partha Sinha <pnsinha68 at gmail.com
>     <mailto:pnsinha68 at gmail.com>> wrote:
>     >
>     > I want to plot a list of 10 numbers. I want to plot each point
>     after 5 secs (first point in o sec and 2nd point after 5 sec anf
>     so on) and want to plot them in same graph.
>     > How to do?
>     > Regards
>     > Parth
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190814/a76890df/attachment.html>


More information about the Matplotlib-users mailing list