From mustapha.adamu at monash.edu Fri May 3 02:53:17 2019 From: mustapha.adamu at monash.edu (Mustapha Adamu) Date: Fri, 3 May 2019 16:53:17 +1000 Subject: [Matplotlib-users] Matplotlib-plotting-based on different condions from different maps Message-ID: Dear all, I need some help with regards to colormaps, I am new to python and unsure how to go about it. I have three spatial correlation maps, lets call the A(72x144), B(72X144) and C(72x144) and each one of these are made of of values from -1 to 1. Now I want to generate one single colomap form these based on the following conditions, For regions where A > 0.5, B > 0.5 and C > 0.5, make those regions red on the new color map, for regions where A>0.5, B = 0 and C = 0 also make those regions Blue. In a coding format I want something like this For in range(x): for J in range(y): if A(i,j) >0 & if B(i,J) > 0.5 & if C>0.5: then colormap = Reds. This is the general idea I have but dont know how to write this and make it actually work with my code. I am open to anwer further questions and I would be most grateful for your help. Thanks Adam. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jklymak at uvic.ca Fri May 3 10:39:43 2019 From: jklymak at uvic.ca (Jody Klymak) Date: Fri, 3 May 2019 07:39:43 -0700 Subject: [Matplotlib-users] Matplotlib-plotting-based on different condions from different maps In-Reply-To: References: Message-ID: Hi Adam, Have a look at `BoundaryNorm` i.e.: https://matplotlib.org/tutorials/colors/colormapnorms.html#discrete-bounds. Feel free to ask further if you have issues with that. However, for your case, you may just want to use pcolormesh and just set the color argument directly. Cheers, Jody > On May 2, 2019, at 23:53 PM, Mustapha Adamu via Matplotlib-users wrote: > > Dear all, > I need some help with regards to colormaps, I am new to python and unsure how to go about it. > > I have three spatial correlation maps, lets call the A(72x144), B(72X144) and C(72x144) and each one of these are made of of values from -1 to 1. > > Now I want to generate one single colomap form these based on the following conditions, > > For regions where A > 0.5, B > 0.5 and C > 0.5, make those regions red on the new color map, for regions where A>0.5, B = 0 and C = 0 also make those regions Blue. > > In a coding format I want something like this > For in range(x): > for J in range(y): > if A(i,j) >0 & if B(i,J) > 0.5 & if C>0.5: > then colormap = Reds. > This is the general idea I have but dont know how to write this and make it actually work with my code. > I am open to anwer further questions and I would be most grateful for your help. > > Thanks > Adam. > > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users From akkana at shallowsky.com Fri May 3 21:09:08 2019 From: akkana at shallowsky.com (Akkana Peck) Date: Fri, 3 May 2019 19:09:08 -0600 Subject: [Matplotlib-users] Autoscaling Date Locator with minor ticks? Message-ID: <20190504010908.GA9339@shallowsky.com> Is there any way to get AutoDateLocator to handle minor ticks as well as major ones? For instance, if I have a plot spanning a few days, I'd like to be able to show the date as a label and major tick, but show minor ticks for hours, or one minor tick every six hours, whatever is sensible depending on the scale. Or on a plot spanning a few years, show labels for each year, but with 12 minor ticks showing months. It seems like AutoDateLocator only draws major ticks. I can write a custom date locator that handles the minor ticks nicely, but then I don't get the nice auto-scaling of AutoDateLocator, and if I plot a larger or smaller date range, my labels and ticks become too crowded or too sparse. I tried setting both major and minor locators to AutoDateLocators: ax.xaxis.set_major_locator(AutoDateLocator()) ax.xaxis.set_minor_locator(AutoDateLocator()) and similarly with set_*_formatter(), but that just gave me smeary-looking double-printed major labels and ticks. Maybe I need to write a custom smart locator that reproduces AutoDateLocator's auto-scaling while also handling ticks. But before I dive into that, I thought I'd ask; I can't be the only person who needs more precise ticks and labeling than AutoDateLocator provides. Thanks! ...Akkana From mustapha.adamu at monash.edu Sun May 5 05:15:59 2019 From: mustapha.adamu at monash.edu (Mustapha Adamu) Date: Sun, 5 May 2019 19:15:59 +1000 Subject: [Matplotlib-users] Making color maps with ranges: Message-ID: Dear all, I am try to make my own colormap, after searching online including stack overflow there is still no luck hence hope to get some help here, Specifically can I devise my own cmap such that from 1-0.5 is red, 0.5-0.25 is blue, 0.25- -0.25 is white, then -0.25- -0.5 green, and last -0.5- -1 is blue My data is 2D spatial data with range -1 to 1 Thanks in ad Cheers, *Mustapha Adamu* -------------- next part -------------- An HTML attachment was scrubbed... URL: From emilia.petrisor at gmail.com Sun May 5 12:18:41 2019 From: emilia.petrisor at gmail.com (empet) Date: Sun, 5 May 2019 09:18:41 -0700 (MST) Subject: [Matplotlib-users] Making color maps with ranges: In-Reply-To: References: Message-ID: <1557073121119-0.post@n5.nabble.com> matplotlib - users mailing list wrote > Dear all, > I am try to make my own colormap, after searching online including stack > overflow there is still no luck hence hope to get some help here, > > Specifically can I devise my own cmap such that from 1-0.5 is red, > 0.5-0.25 > is blue, 0.25- -0.25 is white, then -0.25- -0.5 green, and last -0.5- -1 > is > blue > > My data is 2D spatial data with range -1 to 1 > Thanks in ad > Cheers, > > *Mustapha Adamu* > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@ > https://mail.python.org/mailman/listinfo/matplotlib-users Mustapha, You should define a discrete colormap as follows: boundaries = [-1, -0.5, -0.25, 0.25, 0.5, 1] cmap= colors.ListedColormap(['blue', 'green','white', 'blue', 'red']) norm = colors.BoundaryNorm(boundaries, cmap.N, clip=True) Then the following code: x = np.linspace(0, np.pi, 400) x, y = np.meshgrid(x, x) z = np.sin(x*y) plt.pcolormesh(x, y, z, cmap=cmap, norm=norm) plt.colorbar() generates an image as you wanted: -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From cgiusti at udel.edu Wed May 8 13:02:23 2019 From: cgiusti at udel.edu (cgiusti) Date: Wed, 8 May 2019 10:02:23 -0700 (MST) Subject: [Matplotlib-users] 3d plotting issue Message-ID: <1557334943465-0.post@n5.nabble.com> Dear matplotlib users, I've encountered an issue with 3d plotting that has me completely stumped. Since a recent update that added ipympl, any plot that uses projection='3d' is completely incorrect, even after subsequently removing the package. For example, running the sample parametric line plot code from the mplot3d tutorial located at https://matplotlib.org/mpl_examples/mplot3d/lines3d_demo.py produces the following image Each of the plots looks vaguely like the points being used to generate the plot are sent to random locations, and clearly the axis is upside down -- possibly an error when computing the projection? 2D plotting works as expected, as do other aspects of the package. Any assistance or suggestions (including other places to ask) would be helpful. Details: I have a group of users working in a JupyterHub (0.9.6) environment on a local Ubuntu 17.10 server. The hub uses SystemUserSpawner to create local Docker containers running JupyterLab (0.35.6) environments for individual users. The containers run Ubuntu 17.10, Python 3.6.7 and matplotlib 3.0.3. Plotting was working fine until I recently updated the Docker images to include ipympl to allow the users to make interactive 3d plots. Once the issue above became apparent, I rolled back the dockerfile to the previous, working version (rebuilt using --nocache), but the problem persists. I have built a bare-bones version of the container which includes only the OS packages, python, the current conda versions of notebook, jupyterhub, jupyterlab, and matplotlib, and the problem persists. This minimal Dockerfile is available here: https://www.dropbox.com/s/h3fuej3higaws0r/Dockerfile.min?dl=0 Because it persists across container rebuilds, my best guess is that adding ipympl created or modified a file in the users' home directories, as these are the only directories visible to the containers. I'm happy to provide more detailed information, but don't want to dump things that won't be useful. Thanks for your attention, Chad -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From niklas.berliner at gmail.com Thu May 9 07:17:17 2019 From: niklas.berliner at gmail.com (Niklas Berliner) Date: Thu, 9 May 2019 12:17:17 +0100 Subject: [Matplotlib-users] Hexbin plot, PolyCollection and inconsistent facecolor values In-Reply-To: References: Message-ID: Just a quick update in case somebody else has a similar problem. I needed to call plt.draw() within the Jupyter Notebook cell to populate the polycollection, that is, directly after the plt.hexhin() call and before the print() statement. Cheers, Niklas On Tue, 30 Apr 2019 at 10:02, Niklas Berliner wrote: > Hi, > > I am trying to change the edgecolor of some hexbin patches in a hexbin > plot. Fiddling around with it to understand how this could work, I > encountered a behaviour I cannot understand. I initially opened an issue at > seaborn here https://github.com/mwaskom/seaborn/issues/1734 . I get the > same behaviour with pure matplotlib and am now asking here for help. > > Calling get_facecolors() on the PolyCollection returned by plt.hexbin > gives different results depending on the jupyter notebook cell within which > the call is made. > > Here's my example (assuming the code is run in a notebook, using Python > 3.6.8, NumPy 1.16.2, Matplotlib 3.0.3, Jupyter 4.4.0) > > Cell 1: > ------- > import matplotlib > import matplotlib.pyplot as plt > import numpy as np > ------- > > Cell 2: > ------- > x = np.array([1,1,1,1.5,1.5,2]) > y = np.array([1,1,1,1,1,1]) > ------- > > Cell 3: > ------- > polycollection = plt.hexbin(x, y, C=np.ones(x.shape), > reduce_C_function=np.sum, extent=[1, 2, 0.5, 1.5], gridsize=3, > linewidths=1, edgecolors='face') > print(polycollection.get_facecolors()) > ------- > This plots three hexbins with different counts and different colours. > Here, get_facecolors() returns a (1,4) array, namely, > [[0.12156863 0.46666667 0.70588235 1. ]] > > Cell 4: > ------- > print(polycollection.get_facecolors()) > ------- > When calling get_facecolors() again in the next cell, a (3,4) array is > returned, namely, > [[0.993248 0.906157 0.143936 1. ] > [0.127568 0.566949 0.550556 1. ] > [0.267004 0.004874 0.329415 1. ]] > > > The second array seems to be the correct one I think (there are different > colors for each of the three hexbins). What is happening here? I am very > confused! > > Thanks, > Niklas > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jslavin at cfa.harvard.edu Tue May 14 11:43:44 2019 From: jslavin at cfa.harvard.edu (Slavin, Jonathan) Date: Tue, 14 May 2019 11:43:44 -0400 Subject: [Matplotlib-users] plot with multiple images and colorbar Message-ID: Hi, I've been working on producing a figure using results of a hydro simulation at multiple times. Because the scale of the region of interest changes over time, I want the size of the axes to change. My goal is to make a figure with results of four timesteps, so four images in a row, with each scaled appropriately and with a colorbar on the right. I tried to use ImageGrid, but that doesn't like having different axis scales for the plots - at least it seems to always scale the y axis the same despite my best efforts - though it does a nice job of locating the colorbar. So I went back to subplots, but in that case the colorbar isn't the right size, at least without tweaking the shrink parameter. Also, for some reason there is a lot of space on the right of the plot even when I use subplots_adjust to set right=0.99. There are many ways to place colorbars, I know, but it would seem that my case would not be so unusual that I should need such complex methods to do what I want. Maybe I'm missing something. Any advice would be appreciated. Regards, Jon -- Jonathan D. Slavin Astrophysicist - High Energy Astrophysics Division Center for Astrophysics | Harvard & Smithsonian Office: (617) 496-7981 | Cell: (781) 363-0035 60 Garden Street | MS 83 | Cambridge, MA 02138 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jklymak at uvic.ca Tue May 14 12:02:19 2019 From: jklymak at uvic.ca (Jody Klymak) Date: Tue, 14 May 2019 09:02:19 -0700 Subject: [Matplotlib-users] plot with multiple images and colorbar In-Reply-To: References: Message-ID: Hi Jonathan, If you are setting the aspect ratio of your subplots, space can be missing on the RHS if the setting the aspect ratio causes the subplots to shrink horizontally. The ?solution? to this is to make your *figure* more tall and less wide until the aspect ratio shrink happens in the vertical instead of the horizontal, or don?t set the aspect ratio. Its pretty hard for matplotlib to do this automatically and still do the usual layout for axes that do not have their aspect ratio set, the desired behaviour of which is to make the axes as big as possible. I?m working on a PR to make colorbars automatically match the height of the shown axes, rather than its place holder, but thats non-trivial. Cheers, Jody > On 14 May 2019, at 08:43, Slavin, Jonathan wrote: > > Hi, > > I've been working on producing a figure using results of a hydro simulation at multiple times. Because the scale of the region of interest changes over time, I want the size of the axes to change. My goal is to make a figure with results of four timesteps, so four images in a row, with each scaled appropriately and with a colorbar on the right. I tried to use ImageGrid, but that doesn't like having different axis scales for the plots - at least it seems to always scale the y axis the same despite my best efforts - though it does a nice job of locating the colorbar. > > So I went back to subplots, but in that case the colorbar isn't the right size, at least without tweaking the shrink parameter. Also, for some reason there is a lot of space on the right of the plot even when I use subplots_adjust to set right=0.99. There are many ways to place colorbars, I know, but it would seem that my case would not be so unusual that I should need such complex methods to do what I want. Maybe I'm missing something. Any advice would be appreciated. > > Regards, > Jon > > -- > > Jonathan D. Slavin > Astrophysicist - High Energy Astrophysics Division > Center for Astrophysics | Harvard & Smithsonian > Office: (617) 496-7981 | Cell: (781) 363-0035 > 60 Garden Street | MS 83 | Cambridge, MA 02138 > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users -- Jody Klymak http://web.uvic.ca/~jklymak/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jslavin at cfa.harvard.edu Tue May 14 12:59:40 2019 From: jslavin at cfa.harvard.edu (Slavin, Jonathan) Date: Tue, 14 May 2019 12:59:40 -0400 Subject: [Matplotlib-users] plot with multiple images and colorbar In-Reply-To: References: Message-ID: Hi Jody, I'm not explicitly setting the aspect ratio. It's set, I think, by the shape of the images that are plotted via imshow. Yes, I'd like for the height of the colorbar to match that of the plots. I am able to get it to do that by changing the shape of the plotting window, but it'd be nicer if it worked without having to do that. It all looks good and works as desired when I use ImageGrid and the axis limits are all the same, but if I try to use different ylimits then things go wrong - even with images that have the same aspect ratio. Jon On Tue, May 14, 2019 at 12:02 PM Jody Klymak wrote: > Hi Jonathan, > > If you are setting the aspect ratio of your subplots, space can be missing > on the RHS if the setting the aspect ratio causes the subplots to shrink > horizontally. The ?solution? to this is to make your *figure* more tall > and less wide until the aspect ratio shrink happens in the vertical instead > of the horizontal, or don?t set the aspect ratio. Its pretty hard for > matplotlib to do this automatically and still do the usual layout for axes > that do not have their aspect ratio set, the desired behaviour of which is > to make the axes as big as possible. > > I?m working on a PR to make colorbars automatically match the height of > the shown axes, rather than its place holder, but thats non-trivial. > > Cheers, Jody > > On 14 May 2019, at 08:43, Slavin, Jonathan > wrote: > > Hi, > > I've been working on producing a figure using results of a hydro > simulation at multiple times. Because the scale of the region of interest > changes over time, I want the size of the axes to change. My goal is to > make a figure with results of four timesteps, so four images in a row, with > each scaled appropriately and with a colorbar on the right. I tried to use > ImageGrid, but that doesn't like having different axis scales for the plots > - at least it seems to always scale the y axis the same despite my best > efforts - though it does a nice job of locating the colorbar. > > So I went back to subplots, but in that case the colorbar isn't the right > size, at least without tweaking the shrink parameter. Also, for some reason > there is a lot of space on the right of the plot even when I use > subplots_adjust to set right=0.99. There are many ways to place colorbars, > I know, but it would seem that my case would not be so unusual that I > should need such complex methods to do what I want. Maybe I'm missing > something. Any advice would be appreciated. > > Regards, > Jon > > -- > Jonathan D. Slavin > Astrophysicist - High Energy Astrophysics Division > Center for Astrophysics | Harvard & Smithsonian > Office: (617) 496-7981 | Cell: (781) 363-0035 > 60 Garden Street | MS 83 | Cambridge, MA 02138 > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > > > -- > Jody Klymak > http://web.uvic.ca/~jklymak/ > > > > > > -- Jonathan D. Slavin Astrophysicist - High Energy Astrophysics Division Center for Astrophysics | Harvard & Smithsonian Office: (617) 496-7981 | Cell: (781) 363-0035 60 Garden Street | MS 83 | Cambridge, MA 02138 -------------- next part -------------- An HTML attachment was scrubbed... URL: From diego.avesani at gmail.com Wed May 15 06:20:54 2019 From: diego.avesani at gmail.com (Diego Avesani) Date: Wed, 15 May 2019 12:20:54 +0200 Subject: [Matplotlib-users] double x-axis with defined xtick and inverse order Message-ID: Dear all, I would like to plot a figure with double x-axes. Unfortunately, it seems the ticks of the second x axis do not fit with what I want. Here the example: import numpy as np import matplotlib.pyplot as plt MM = np.array([ 1., 2., 4., 8., 16., 32.]) SS = np.array([64., 32., 16., 8., 4., 2.]) RR = np.array([2813, 1544, 895, 562, 459,409]) ax = plt.subplot(111) ax.grid(True,which="both",ls="-",color='0.6') ax.plot(MM, RR ,'-r') ax2 = ax.twiny() ax2.invert_xaxis() ax2.plot(MM, RR, 'none') ax2.set_xticks([64,32,16,8,4,2]) ax2.set_xticklabels(['64','32','16','8','4','2']) plt.show() As it can be noticed, the value 32 in the ax2 does not correspond to the second value but is put in the middle point of ax2. I would like to have it in the same vertical line of the second value of MM. This of course not only for 32 but for the value in SS. Basically I would like to have the main axis according to MM and a second ax with SS value in the same line of MM values. I hope I made myself clear. really really thanks and, best regards Diego -------------- next part -------------- An HTML attachment was scrubbed... URL: From filip at ownit.nu Fri May 17 05:19:26 2019 From: filip at ownit.nu (FilipPersson) Date: Fri, 17 May 2019 02:19:26 -0700 (MST) Subject: [Matplotlib-users] Matplotlib plots display as blank in interactive mode with no error messages - (one) Solution Message-ID: <1558084766050-0.post@n5.nabble.com> I spent several hours googling and trying myself to change my code to fix this. No luck in googling and the fact that there was a kind of doing brain surgery on Matplotlib by uninstall, re-install and update and change backend library for a similar but not quite the same problem made me think that I should post the solution somewhere since it was almost impossible to spot. If you get plots like this: Which, as you see gives no error output - not even when clicking on the graph. Actually, nothing at all happens when clicking on the graph. Interactivity is lost. It could be a LaTeX problem causing it! The reason for the blank plot was that I had used a LaTeX escape character for the value 0 when creating nice labels for the x axis. Apparently, using '$\0$' to write the number zero in LaTeX makes the plots blank and kills the interactivity. Restarting the kernel did no good. If I instead write '$0$' as a label, everything works fine again. My environment is Mac OSX 10.13.6, Matplotlib 3.0.2, Python 3.7.1, running in Jupyter (notebook server version 5.7.4, IPython 7.2.0) in Safari Version 12.0 (13606.2.11). If you want to see my code, please request it and then I will post it. -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From oren.a4 at gmail.com Fri May 17 08:51:05 2019 From: oren.a4 at gmail.com (oren) Date: Fri, 17 May 2019 05:51:05 -0700 (MST) Subject: [Matplotlib-users] Editable text from matplotlib? In-Reply-To: References: <649847CE7F259144A0FD99AC64E7326D12B979@MLBXV17.nih.gov> <9D9A79EA-32CE-403F-839A-EE0E0A0C9DFD@alum.mit.edu> Message-ID: <1558097465121-0.post@n5.nabble.com> To change teh text form path to text use this line: matplotlib.rcParams['pdf.fonttype'] = 42 Read more here: http://physicalmodelingwithpython.blogspot.com/2015/06/making-plots-for-publication.html -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From tcaswell at gmail.com Fri May 17 09:58:37 2019 From: tcaswell at gmail.com (Thomas Caswell) Date: Fri, 17 May 2019 09:58:37 -0400 Subject: [Matplotlib-users] Matplotlib plots display as blank in interactive mode with no error messages - (one) Solution In-Reply-To: <1558084766050-0.post@n5.nabble.com> References: <1558084766050-0.post@n5.nabble.com> Message-ID: This is possible related to https://github.com/matplotlib/matplotlib/issues/13988 . What backend are you using? Tom On Fri, May 17, 2019 at 5:19 AM FilipPersson wrote: > I spent several hours googling and trying myself to change my code to fix > this. No luck in googling and the fact that there was a kind of doing brain > surgery on Matplotlib by uninstall, re-install and update and change > backend > library for a similar but not quite the same problem made me think that I > should post the solution somewhere since it was almost impossible to spot. > > If you get plots like this: > > Which, as you see gives no error output - not even when clicking on the > graph. Actually, nothing at all happens when clicking on the graph. > Interactivity is lost. > > It could be a LaTeX problem causing it! > The reason for the blank plot was that I had used a LaTeX escape character > for the value 0 when creating nice labels for the x axis. Apparently, using > '$\0$' to write the number zero in LaTeX makes the plots blank and kills > the > interactivity. Restarting the kernel did no good. > If I instead write '$0$' as a label, everything works fine again. > > My environment is Mac OSX 10.13.6, Matplotlib 3.0.2, Python 3.7.1, running > in Jupyter (notebook server version 5.7.4, IPython 7.2.0) in Safari Version > 12.0 (13606.2.11). > > If you want to see my code, please request it and then I will post it. > > > > -- > Sent from: > http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -- Thomas Caswell tcaswell at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From tcaswell at gmail.com Sat May 18 15:25:32 2019 From: tcaswell at gmail.com (Thomas Caswell) Date: Sat, 18 May 2019 15:25:32 -0400 Subject: [Matplotlib-users] REL: Matplotlib 3.1.0 Message-ID: Folks, We are happy to announce the release of Matplotlib 3.1! Matplotlib 3.1 supports Python 3.6+. Highlights of this release include: - A helper method for scatter legends - Secondary axis support (ex, degrees and radians) - A concise date formatter - No longer requires a framework build of Python to use OSX backend - Major and minor ticks will no longer collide by default - A progress callback for animations - mplot3D is always registered - deprecated mlab functions have been removed - Many function calls have become stricter about invalid or ignored input For the full details see - whats new: https://matplotlib.org/users/whats_new.html - API changes: https://matplotlib.org/api/api_changes.html A big thank you to everyone who worked on this release including the 151 people contributed code [1] and the many more who reported issues. We are planning to have Matplotlib 3.2 released in September/October and Matplotlib 2.2.5 (the final release of the 2.2.x LTS series) in December. Tom [1] https://matplotlib.org/users/github_stats.html -- Thomas Caswell tcaswell at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From farukerdemoncel at gmail.com Sat May 18 17:58:46 2019 From: farukerdemoncel at gmail.com (Erdem) Date: Sun, 19 May 2019 00:58:46 +0300 Subject: [Matplotlib-users] Convolution integral export as animation Message-ID: This example is taken from a tutorial related to convolution integral. I would like to export this example as animation in mp4 format. So far, the code looks like this : import scipy.integrateimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animation def showConvolution(t0,f1, f2): # Calculate the overall convolution result using Simpson integration convolution = np.zeros(len(t)) for n, t_ in enumerate(t): prod = lambda tau: f1(tau) * f2(t_-tau) convolution[n] = scipy.integrate.simps(prod(t), t) # Create the shifted and flipped function f_shift = lambda t: f2(t0-t) prod = lambda tau: f1(tau) * f2(t0-tau) # Plot the curves plt.gcf().clear() # il plt.subplot(211) plt.gca().set_ymargin(0.05) # il plt.plot(t, f1(t), label=r'$f_1(\tau)$') plt.plot(t, f_shift(t), label=r'$f_2(t_0-\tau)$') plt.fill(t, prod(t), color='r', alpha=0.5, edgecolor='black', hatch='//') # il plt.plot(t, prod(t), 'r-', label=r'$f_1(\tau)f_2(t_0-\tau)$') plt.grid(True); plt.xlabel(r'$\tau$'); plt.ylabel(r'$x(\tau)$') # il plt.legend(fontsize=10) # il plt.text(-4, 0.6, '$t_0=%.2f$' % t0, bbox=dict(fc='white')) # il # plot the convolution curve plt.subplot(212) plt.gca().set_ymargin(0.05) # il plt.plot(t, convolution, label='$(f_1*f_2)(t)$') # recalculate the value of the convolution integral at the current time-shift t0 current_value = scipy.integrate.simps(prod(t), t) plt.plot(t0, current_value, 'ro') # plot the point plt.grid(True); plt.xlabel('$t$'); plt.ylabel('$(f_1*f_2)(t)$') # il plt.legend(fontsize=10) # il plt.show() # il Fs = 50 # our sampling frequency for the plotting T = 5 # the time range we are interested in t = np.arange(-T, T, 1/Fs) # the time samples f1 = lambda t: np.maximum(0, 1-abs(t)) f2 = lambda t: (t>0) * np.exp(-2*t) t0 = np.arange(-2.0,2.0, 0.05) fig = plt.figure(figsize=(8,3)) anim = animation.FuncAnimation(fig, showConvolution, frames=t0, fargs=(f1,f2),interval=80) anim.save('animation.mp4', fps=30) # fps = frames per second plt.show() Is there a way to change t0 so that I'd like to able to save it as animation as in the tutorial In the example t0 decreases from -2.0 to -1.95 etc the green curve is shifted right, and the area between curves, product increases. In the tutorial there is an html animation and I would like to save as mp4 file. I've also added code as an attachment. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: convolution.py Type: text/x-python Size: 2029 bytes Desc: not available URL: From farukerdemoncel at gmail.com Sat May 18 18:05:10 2019 From: farukerdemoncel at gmail.com (Erdem) Date: Sun, 19 May 2019 01:05:10 +0300 Subject: [Matplotlib-users] Convolution integral export as animation Message-ID: This example is taken from a tutorial related to convolution integral. I would like to export this example as animation in mp4 format. So far, the code looks like this : import scipy.integrateimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animation def showConvolution(t0,f1, f2): # Calculate the overall convolution result using Simpson integration convolution = np.zeros(len(t)) for n, t_ in enumerate(t): prod = lambda tau: f1(tau) * f2(t_-tau) convolution[n] = scipy.integrate.simps(prod(t), t) # Create the shifted and flipped function f_shift = lambda t: f2(t0-t) prod = lambda tau: f1(tau) * f2(t0-tau) # Plot the curves plt.gcf().clear() # il plt.subplot(211) plt.gca().set_ymargin(0.05) # il plt.plot(t, f1(t), label=r'$f_1(\tau)$') plt.plot(t, f_shift(t), label=r'$f_2(t_0-\tau)$') plt.fill(t, prod(t), color='r', alpha=0.5, edgecolor='black', hatch='//') # il plt.plot(t, prod(t), 'r-', label=r'$f_1(\tau)f_2(t_0-\tau)$') plt.grid(True); plt.xlabel(r'$\tau$'); plt.ylabel(r'$x(\tau)$') # il plt.legend(fontsize=10) # il plt.text(-4, 0.6, '$t_0=%.2f$' % t0, bbox=dict(fc='white')) # il # plot the convolution curve plt.subplot(212) plt.gca().set_ymargin(0.05) # il plt.plot(t, convolution, label='$(f_1*f_2)(t)$') # recalculate the value of the convolution integral at the current time-shift t0 current_value = scipy.integrate.simps(prod(t), t) plt.plot(t0, current_value, 'ro') # plot the point plt.grid(True); plt.xlabel('$t$'); plt.ylabel('$(f_1*f_2)(t)$') # il plt.legend(fontsize=10) # il plt.show() # il Fs = 50 # our sampling frequency for the plotting T = 5 # the time range we are interested in t = np.arange(-T, T, 1/Fs) # the time samples f1 = lambda t: np.maximum(0, 1-abs(t)) f2 = lambda t: (t>0) * np.exp(-2*t) t0 = np.arange(-2.0,2.0, 0.05) fig = plt.figure(figsize=(8,3)) anim = animation.FuncAnimation(fig, showConvolution, frames=t0, fargs=(f1,f2),interval=80) anim.save('animation.mp4', fps=30) # fps = frames per second plt.show() When I run the program I see the output of see the output of convolution integral at t0 = -0.20. [image: convolution.png] Is there a way to change t0 so that I'd like to able to save it as animation as in the tutorial In the example t0 decreases from -2.0 to -1.95 etc the green curve is shifted right, and the area between curves, product increases. In the tutorial there is an html animation and I would like to save as mp4 file. I've also added source code as an attachment. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: convolution.png Type: image/png Size: 36111 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: convolution.py Type: text/x-python Size: 2029 bytes Desc: not available URL: From filip at ownit.nu Sun May 19 03:50:50 2019 From: filip at ownit.nu (FilipPersson) Date: Sun, 19 May 2019 00:50:50 -0700 (MST) Subject: [Matplotlib-users] Matplotlib plots display as blank in interactive mode with no error messages - (one) Solution In-Reply-To: References: <1558084766050-0.post@n5.nabble.com> Message-ID: <1558252250113-0.post@n5.nabble.com> Hi Tom, I'm not sure if it's related. I'm using nbAgg. It acme automatically when I installed and I haven't changed it. Their plots go black. Not all my plots go crazy when I do the escape character error, only the interactive ones when re-running. -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From tcaswell at gmail.com Sun May 19 17:16:48 2019 From: tcaswell at gmail.com (Thomas Caswell) Date: Sun, 19 May 2019 17:16:48 -0400 Subject: [Matplotlib-users] Convolution integral export as animation In-Reply-To: References: Message-ID: Erdem, I do not understand your question. If I run that code I do get an mp4 file of the animation. Tom On Sat, May 18, 2019 at 6:05 PM Erdem wrote: > This example is taken from a tutorial > related > to convolution integral. > > I would like to export this example as animation in mp4 format. So far, > the code looks like this : > > import scipy.integrateimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animation > def showConvolution(t0,f1, f2): > # Calculate the overall convolution result using Simpson integration > convolution = np.zeros(len(t)) > for n, t_ in enumerate(t): > prod = lambda tau: f1(tau) * f2(t_-tau) > convolution[n] = scipy.integrate.simps(prod(t), t) > > # Create the shifted and flipped function > f_shift = lambda t: f2(t0-t) > prod = lambda tau: f1(tau) * f2(t0-tau) > > # Plot the curves > plt.gcf().clear() # il > > plt.subplot(211) > plt.gca().set_ymargin(0.05) # il > plt.plot(t, f1(t), label=r'$f_1(\tau)$') > plt.plot(t, f_shift(t), label=r'$f_2(t_0-\tau)$') > plt.fill(t, prod(t), color='r', alpha=0.5, edgecolor='black', hatch='//') # il > plt.plot(t, prod(t), 'r-', label=r'$f_1(\tau)f_2(t_0-\tau)$') > plt.grid(True); plt.xlabel(r'$\tau$'); plt.ylabel(r'$x(\tau)$') # il > plt.legend(fontsize=10) # il > plt.text(-4, 0.6, '$t_0=%.2f$' % t0, bbox=dict(fc='white')) # il > > # plot the convolution curve > plt.subplot(212) > plt.gca().set_ymargin(0.05) # il > plt.plot(t, convolution, label='$(f_1*f_2)(t)$') > > # recalculate the value of the convolution integral at the current time-shift t0 > current_value = scipy.integrate.simps(prod(t), t) > plt.plot(t0, current_value, 'ro') # plot the point > plt.grid(True); plt.xlabel('$t$'); plt.ylabel('$(f_1*f_2)(t)$') # il > plt.legend(fontsize=10) # il > plt.show() # il > Fs = 50 # our sampling frequency for the plotting > T = 5 # the time range we are interested in > t = np.arange(-T, T, 1/Fs) # the time samples > f1 = lambda t: np.maximum(0, 1-abs(t)) > f2 = lambda t: (t>0) * np.exp(-2*t) > > t0 = np.arange(-2.0,2.0, 0.05) > > fig = plt.figure(figsize=(8,3)) > anim = animation.FuncAnimation(fig, showConvolution, frames=t0, fargs=(f1,f2),interval=80) > > anim.save('animation.mp4', fps=30) # fps = frames per second > > plt.show() > > > When I run the program I see the output of see the output of convolution > integral at t0 = -0.20. > > [image: convolution.png] > > Is there a way to change t0 so that I'd like to able to save it as > animation as in the tutorial > In > the example t0 decreases from -2.0 to -1.95 etc the green curve is shifted > right, and the area between curves, product increases. In the tutorial > there is an html animation and I would like to save as mp4 file. > > I've also added source code as an attachment. > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -- Thomas Caswell tcaswell at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: convolution.png Type: image/png Size: 36111 bytes Desc: not available URL: From tcaswell at gmail.com Sun May 19 18:05:45 2019 From: tcaswell at gmail.com (Thomas Caswell) Date: Sun, 19 May 2019 18:05:45 -0400 Subject: [Matplotlib-users] Convolution integral export as animation In-Reply-To: References: Message-ID: Please don't drop the mailing list from the replies. Ah, I ran it by invoking the script in an IPython session where `plt.ion()` has been called and `plt.show()` in non-blocking. If I run it as as script I see what you descirbe! Removing the `plt.show()` calls from inside of the re-draw function allows it to run end-to-end and write out the animation. Tom On Sun, May 19, 2019 at 5:59 PM Erdem wrote: > Thank you very much. > > My operating system is Ubuntu 18.04 LTS 64 bit. I've set up a virtual > python environment and to activate I use this command. > > $ . venv/bin/activate > > I've saved source file as convolution py. To run the source code I use > this command > > $ python convolution.py > > But rather than an animation I see only a plot of integral at t0=-2.00 > > [image: convolution.png] > > I wait some time and nothing happens. I've also tried to close window a > few times and the result is same. > > Since you may be able to get an mp4 file of the animation may it be > because of some codecs are missing or may be a bug? > > Erdem > > Thomas Caswell , 20 May 2019 Pzt, 00:17 tarihinde > ?unu yazd?: > >> Erdem, >> >> I do not understand your question. If I run that code I do get an mp4 >> file of the animation. >> >> Tom >> >> >> On Sat, May 18, 2019 at 6:05 PM Erdem wrote: >> >>> This example is taken from a tutorial >>> related >>> to convolution integral. >>> >>> I would like to export this example as animation in mp4 format. So far, >>> the code looks like this : >>> >>> import scipy.integrateimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animation >>> def showConvolution(t0,f1, f2): >>> # Calculate the overall convolution result using Simpson integration >>> convolution = np.zeros(len(t)) >>> for n, t_ in enumerate(t): >>> prod = lambda tau: f1(tau) * f2(t_-tau) >>> convolution[n] = scipy.integrate.simps(prod(t), t) >>> >>> # Create the shifted and flipped function >>> f_shift = lambda t: f2(t0-t) >>> prod = lambda tau: f1(tau) * f2(t0-tau) >>> >>> # Plot the curves >>> plt.gcf().clear() # il >>> >>> plt.subplot(211) >>> plt.gca().set_ymargin(0.05) # il >>> plt.plot(t, f1(t), label=r'$f_1(\tau)$') >>> plt.plot(t, f_shift(t), label=r'$f_2(t_0-\tau)$') >>> plt.fill(t, prod(t), color='r', alpha=0.5, edgecolor='black', hatch='//') # il >>> plt.plot(t, prod(t), 'r-', label=r'$f_1(\tau)f_2(t_0-\tau)$') >>> plt.grid(True); plt.xlabel(r'$\tau$'); plt.ylabel(r'$x(\tau)$') # il >>> plt.legend(fontsize=10) # il >>> plt.text(-4, 0.6, '$t_0=%.2f$' % t0, bbox=dict(fc='white')) # il >>> >>> # plot the convolution curve >>> plt.subplot(212) >>> plt.gca().set_ymargin(0.05) # il >>> plt.plot(t, convolution, label='$(f_1*f_2)(t)$') >>> >>> # recalculate the value of the convolution integral at the current time-shift t0 >>> current_value = scipy.integrate.simps(prod(t), t) >>> plt.plot(t0, current_value, 'ro') # plot the point >>> plt.grid(True); plt.xlabel('$t$'); plt.ylabel('$(f_1*f_2)(t)$') # il >>> plt.legend(fontsize=10) # il >>> plt.show() # il >>> Fs = 50 # our sampling frequency for the plotting >>> T = 5 # the time range we are interested in >>> t = np.arange(-T, T, 1/Fs) # the time samples >>> f1 = lambda t: np.maximum(0, 1-abs(t)) >>> f2 = lambda t: (t>0) * np.exp(-2*t) >>> >>> t0 = np.arange(-2.0,2.0, 0.05) >>> >>> fig = plt.figure(figsize=(8,3)) >>> anim = animation.FuncAnimation(fig, showConvolution, frames=t0, fargs=(f1,f2),interval=80) >>> >>> anim.save('animation.mp4', fps=30) # fps = frames per second >>> >>> plt.show() >>> >>> >>> When I run the program I see the output of see the output of convolution >>> integral at t0 = -0.20. >>> >>> [image: convolution.png] >>> >>> Is there a way to change t0 so that I'd like to able to save it as >>> animation as in the tutorial >>> In >>> the example t0 decreases from -2.0 to -1.95 etc the green curve is shifted >>> right, and the area between curves, product increases. In the tutorial >>> there is an html animation and I would like to save as mp4 file. >>> >>> I've also added source code as an attachment. >>> _______________________________________________ >>> Matplotlib-users mailing list >>> Matplotlib-users at python.org >>> https://mail.python.org/mailman/listinfo/matplotlib-users >>> >> >> >> -- >> Thomas Caswell >> tcaswell at gmail.com >> > -- Thomas Caswell tcaswell at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: convolution.png Type: image/png Size: 36111 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: convolution.png Type: image/png Size: 36111 bytes Desc: not available URL: From tcaswell at gmail.com Sun May 19 18:24:30 2019 From: tcaswell at gmail.com (Thomas Caswell) Date: Sun, 19 May 2019 18:24:30 -0400 Subject: [Matplotlib-users] Convolution integral export as animation In-Reply-To: References: Message-ID: Try 'reply-all' instead? Yes, that is controlled by the fps kwarg to `anim.save`. Glad it is working! Tom On Sun, May 19, 2019 at 6:23 PM Erdem wrote: > My reply does not show in the mail list. I have no idea why this happened > but I simply use Gmail to reply. I used to use Gnus message reader with > Emacs but I think it is not installed for now. > > Thanks now it works as expected! > > Is there a way to slow down animation a bit. > > Erdem > > > Thomas Caswell , 20 May 2019 Pzt, 01:05 tarihinde > ?unu yazd?: > >> Please don't drop the mailing list from the replies. >> >> Ah, I ran it by invoking the script in an IPython session where >> `plt.ion()` has been called and `plt.show()` in non-blocking. If I run it >> as as script I see what you descirbe! >> >> Removing the `plt.show()` calls from inside of the re-draw function >> allows it to run end-to-end and write out the animation. >> >> Tom >> >> On Sun, May 19, 2019 at 5:59 PM Erdem wrote: >> >>> Thank you very much. >>> >>> My operating system is Ubuntu 18.04 LTS 64 bit. I've set up a virtual >>> python environment and to activate I use this command. >>> >>> $ . venv/bin/activate >>> >>> I've saved source file as convolution py. To run the source code I use >>> this command >>> >>> $ python convolution.py >>> >>> But rather than an animation I see only a plot of integral at t0=-2.00 >>> >>> [image: convolution.png] >>> >>> I wait some time and nothing happens. I've also tried to close window a >>> few times and the result is same. >>> >>> Since you may be able to get an mp4 file of the animation may it be >>> because of some codecs are missing or may be a bug? >>> >>> Erdem >>> >>> Thomas Caswell , 20 May 2019 Pzt, 00:17 tarihinde >>> ?unu yazd?: >>> >>>> Erdem, >>>> >>>> I do not understand your question. If I run that code I do get an mp4 >>>> file of the animation. >>>> >>>> Tom >>>> >>>> >>>> On Sat, May 18, 2019 at 6:05 PM Erdem >>>> wrote: >>>> >>>>> This example is taken from a tutorial >>>>> related >>>>> to convolution integral. >>>>> >>>>> I would like to export this example as animation in mp4 format. So >>>>> far, the code looks like this : >>>>> >>>>> import scipy.integrateimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animation >>>>> def showConvolution(t0,f1, f2): >>>>> # Calculate the overall convolution result using Simpson integration >>>>> convolution = np.zeros(len(t)) >>>>> for n, t_ in enumerate(t): >>>>> prod = lambda tau: f1(tau) * f2(t_-tau) >>>>> convolution[n] = scipy.integrate.simps(prod(t), t) >>>>> >>>>> # Create the shifted and flipped function >>>>> f_shift = lambda t: f2(t0-t) >>>>> prod = lambda tau: f1(tau) * f2(t0-tau) >>>>> >>>>> # Plot the curves >>>>> plt.gcf().clear() # il >>>>> >>>>> plt.subplot(211) >>>>> plt.gca().set_ymargin(0.05) # il >>>>> plt.plot(t, f1(t), label=r'$f_1(\tau)$') >>>>> plt.plot(t, f_shift(t), label=r'$f_2(t_0-\tau)$') >>>>> plt.fill(t, prod(t), color='r', alpha=0.5, edgecolor='black', hatch='//') # il >>>>> plt.plot(t, prod(t), 'r-', label=r'$f_1(\tau)f_2(t_0-\tau)$') >>>>> plt.grid(True); plt.xlabel(r'$\tau$'); plt.ylabel(r'$x(\tau)$') # il >>>>> plt.legend(fontsize=10) # il >>>>> plt.text(-4, 0.6, '$t_0=%.2f$' % t0, bbox=dict(fc='white')) # il >>>>> >>>>> # plot the convolution curve >>>>> plt.subplot(212) >>>>> plt.gca().set_ymargin(0.05) # il >>>>> plt.plot(t, convolution, label='$(f_1*f_2)(t)$') >>>>> >>>>> # recalculate the value of the convolution integral at the current time-shift t0 >>>>> current_value = scipy.integrate.simps(prod(t), t) >>>>> plt.plot(t0, current_value, 'ro') # plot the point >>>>> plt.grid(True); plt.xlabel('$t$'); plt.ylabel('$(f_1*f_2)(t)$') # il >>>>> plt.legend(fontsize=10) # il >>>>> plt.show() # il >>>>> Fs = 50 # our sampling frequency for the plotting >>>>> T = 5 # the time range we are interested in >>>>> t = np.arange(-T, T, 1/Fs) # the time samples >>>>> f1 = lambda t: np.maximum(0, 1-abs(t)) >>>>> f2 = lambda t: (t>0) * np.exp(-2*t) >>>>> >>>>> t0 = np.arange(-2.0,2.0, 0.05) >>>>> >>>>> fig = plt.figure(figsize=(8,3)) >>>>> anim = animation.FuncAnimation(fig, showConvolution, frames=t0, fargs=(f1,f2),interval=80) >>>>> >>>>> anim.save('animation.mp4', fps=30) # fps = frames per second >>>>> >>>>> plt.show() >>>>> >>>>> >>>>> When I run the program I see the output of see the output of >>>>> convolution integral at t0 = -0.20. >>>>> >>>>> [image: convolution.png] >>>>> >>>>> Is there a way to change t0 so that I'd like to able to save it as >>>>> animation as in the tutorial >>>>> In >>>>> the example t0 decreases from -2.0 to -1.95 etc the green curve is shifted >>>>> right, and the area between curves, product increases. In the tutorial >>>>> there is an html animation and I would like to save as mp4 file. >>>>> >>>>> I've also added source code as an attachment. >>>>> _______________________________________________ >>>>> Matplotlib-users mailing list >>>>> Matplotlib-users at python.org >>>>> https://mail.python.org/mailman/listinfo/matplotlib-users >>>>> >>>> >>>> >>>> -- >>>> Thomas Caswell >>>> tcaswell at gmail.com >>>> >>> >> >> -- >> Thomas Caswell >> tcaswell at gmail.com >> > -- Thomas Caswell tcaswell at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: convolution.png Type: image/png Size: 36111 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: convolution.png Type: image/png Size: 36111 bytes Desc: not available URL: From tcaswell at gmail.com Sun May 19 18:54:45 2019 From: tcaswell at gmail.com (Thomas Caswell) Date: Sun, 19 May 2019 18:54:45 -0400 Subject: [Matplotlib-users] Matplotlib plots display as blank in interactive mode with no error messages - (one) Solution In-Reply-To: <1558252250113-0.post@n5.nabble.com> References: <1558084766050-0.post@n5.nabble.com> <1558252250113-0.post@n5.nabble.com> Message-ID: Indeed, sorry for the misdirection. If you look in your terminal do you see a bunch of tracebacks? The problem is that Python read \0 in a string literal as an escaped 0 byte (aka \x00) which fails to parse with with mathtex and latex. If you make a raw string (r"$\0$") python won't interpret the escape character, but both mathtex and latex still fail as \0 is not a valid command it latex. These exceptions are being raised as part of the draw process which cause it to fail which makes it look like interactivity is lost because the updated image is not shipped to the browser. We should sort out a better way to surface those exceptions, the problem is that they happen asynchronously so it is not clear where they should be raised... Tom On Sun, May 19, 2019 at 3:51 AM FilipPersson wrote: > Hi Tom, > I'm not sure if it's related. I'm using nbAgg. It acme automatically when I > installed and I haven't changed it. Their plots go black. Not all my plots > go crazy when I do the escape character error, only the interactive ones > when re-running. > > > > -- > Sent from: > http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -- Thomas Caswell tcaswell at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From heiland at iu.edu Tue May 21 11:42:26 2019 From: heiland at iu.edu (Heiland, Randy) Date: Tue, 21 May 2019 15:42:26 +0000 Subject: [Matplotlib-users] scatter plot with data coord sized glyphs Message-ID: <690CAFBA-17E4-49AE-913C-78EC7169F747@iu.edu> Hello, Is it possible to specify scatter plot glyph sizes - specifically, circles and, e.g., radii, in data coords, rather than ?marker size? of ?points**2?? thanks, Randy -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 4054 bytes Desc: not available URL: From selasley at icloud.com Tue May 21 12:35:29 2019 From: selasley at icloud.com (Scott Lasley) Date: Tue, 21 May 2019 12:35:29 -0400 Subject: [Matplotlib-users] scatter plot with data coord sized glyphs In-Reply-To: <690CAFBA-17E4-49AE-913C-78EC7169F747@iu.edu> References: <690CAFBA-17E4-49AE-913C-78EC7169F747@iu.edu> Message-ID: <1B9962D3-8260-4EB3-AB3A-0F065977EEA5@icloud.com> Syrtis Major's gist at https://gist.github.com/syrte/592a062c562cd2a98a83 seems to do what you want. See this stackoverflow answer for an example of the circles function in action - https://stackoverflow.com/questions/9081553/python-scatter-plot-size-and-style-of-the-marker/24567352#24567352 hth, Scott > On May 21, 2019, at 11:42 AM, Heiland, Randy wrote: > > Hello, > Is it possible to specify scatter plot glyph sizes - specifically, circles and, e.g., radii, in data coords, rather than ?marker size? of ?points**2?? > thanks, Randy From heiland at iu.edu Tue May 21 14:08:32 2019 From: heiland at iu.edu (Heiland, Randy) Date: Tue, 21 May 2019 18:08:32 +0000 Subject: [Matplotlib-users] scatter plot with data coord sized glyphs In-Reply-To: <1B9962D3-8260-4EB3-AB3A-0F065977EEA5@icloud.com> References: <690CAFBA-17E4-49AE-913C-78EC7169F747@iu.edu> <1B9962D3-8260-4EB3-AB3A-0F065977EEA5@icloud.com> Message-ID: Thanks Scott! That certainly gets me closer. One question/problem I still have is that it doesn?t seem to like RGB as colors, in spite of the docs. I?ve attached a simple example. Randy -------------- next part -------------- A non-text attachment was scrubbed... Name: test_circ2.py Type: text/x-python-script Size: 3148 bytes Desc: not available URL: -------------- next part -------------- > On May 21, 2019, at 12:35 PM, Scott Lasley wrote: > > Syrtis Major's gist at https://gist.github.com/syrte/592a062c562cd2a98a83 seems to do what you want. See this stackoverflow answer for an example of the circles function in action - > https://stackoverflow.com/questions/9081553/python-scatter-plot-size-and-style-of-the-marker/24567352#24567352 > > hth, > Scott > >> On May 21, 2019, at 11:42 AM, Heiland, Randy wrote: >> >> Hello, >> Is it possible to specify scatter plot glyph sizes - specifically, circles and, e.g., radii, in data coords, rather than ?marker size? of ?points**2?? >> thanks, Randy -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 4054 bytes Desc: not available URL: From selasley at icloud.com Tue May 21 14:39:28 2019 From: selasley at icloud.com (Scott Lasley) Date: Tue, 21 May 2019 14:39:28 -0400 Subject: [Matplotlib-users] scatter plot with data coord sized glyphs In-Reply-To: References: <690CAFBA-17E4-49AE-913C-78EC7169F747@iu.edu> <1B9962D3-8260-4EB3-AB3A-0F065977EEA5@icloud.com> Message-ID: <61CE5312-0DF1-491E-80EA-4FB44ECB9642@icloud.com> From the docstring in circles - "Note that `c` should not be a single numeric RGB or RGBA sequence because that is indistinguishable from an array of values to be colormapped. (If you insist, use `color` instead). So a slight modification of your code seems to do what you want fig = plt.figure(figsize=(5,3)) ax = fig.gca() ax.set_aspect("equal") xvals = np.array([0,100]) yvals = np.array([0,0]) rvals = np.array([30,10]) rgb = np.array([[255, 0, 0], [0, 255, 0]]) circles(xvals, yvals, s=rvals, color=rgb / 255.) # use color instead of c and make 0. <= rgb <= 1. plt.xlim(-30,110) plt.ylim(-30,30) plt.show() Scott > On May 21, 2019, at 2:08 PM, Heiland, Randy wrote: > > Thanks Scott! That certainly gets me closer. One question/problem I still have is that it doesn?t seem to like RGB as colors, in spite of the docs. I?ve attached a simple example. > > Randy > > > >> On May 21, 2019, at 12:35 PM, Scott Lasley wrote: >> >> Syrtis Major's gist at https://gist.github.com/syrte/592a062c562cd2a98a83 seems to do what you want. See this stackoverflow answer for an example of the circles function in action - >> https://stackoverflow.com/questions/9081553/python-scatter-plot-size-and-style-of-the-marker/24567352#24567352 >> >> hth, >> Scott >> >>> On May 21, 2019, at 11:42 AM, Heiland, Randy wrote: >>> >>> Hello, >>> Is it possible to specify scatter plot glyph sizes - specifically, circles and, e.g., radii, in data coords, rather than ?marker size? of ?points**2?? >>> thanks, Randy > From heiland at iu.edu Wed May 22 07:15:55 2019 From: heiland at iu.edu (Heiland, Randy) Date: Wed, 22 May 2019 11:15:55 +0000 Subject: [Matplotlib-users] scatter plot with data coord sized glyphs In-Reply-To: <61CE5312-0DF1-491E-80EA-4FB44ECB9642@icloud.com> References: <690CAFBA-17E4-49AE-913C-78EC7169F747@iu.edu> <1B9962D3-8260-4EB3-AB3A-0F065977EEA5@icloud.com> <61CE5312-0DF1-491E-80EA-4FB44ECB9642@icloud.com> Message-ID: <4CF15809-8DF6-4311-83F1-760BCADA823A@iu.edu> Scott, thanks for the help once again! Yes, the results are exactly what I want, and seem to be quite fast for lots of circles. Randy > On May 21, 2019, at 2:39 PM, Scott Lasley wrote: > > From the docstring in circles - "Note that `c` should not be a single numeric RGB or RGBA sequence because that is indistinguishable from an array of values to be colormapped. (If you insist, use `color` instead). So a slight modification of your code seems to do what you want > > > fig = plt.figure(figsize=(5,3)) > ax = fig.gca() > ax.set_aspect("equal") > > xvals = np.array([0,100]) > yvals = np.array([0,0]) > rvals = np.array([30,10]) > > rgb = np.array([[255, 0, 0], [0, 255, 0]]) > > circles(xvals, yvals, s=rvals, color=rgb / 255.) # use color instead of c and make 0. <= rgb <= 1. > > plt.xlim(-30,110) > plt.ylim(-30,30) > plt.show() > > Scott > > >> On May 21, 2019, at 2:08 PM, Heiland, Randy wrote: >> >> Thanks Scott! That certainly gets me closer. One question/problem I still have is that it doesn?t seem to like RGB as colors, in spite of the docs. I?ve attached a simple example. >> >> Randy >> >> >> >>> On May 21, 2019, at 12:35 PM, Scott Lasley wrote: >>> >>> Syrtis Major's gist at https://gist.github.com/syrte/592a062c562cd2a98a83 seems to do what you want. See this stackoverflow answer for an example of the circles function in action - >>> https://stackoverflow.com/questions/9081553/python-scatter-plot-size-and-style-of-the-marker/24567352#24567352 >>> >>> hth, >>> Scott >>> >>>> On May 21, 2019, at 11:42 AM, Heiland, Randy wrote: >>>> >>>> Hello, >>>> Is it possible to specify scatter plot glyph sizes - specifically, circles and, e.g., radii, in data coords, rather than ?marker size? of ?points**2?? >>>> thanks, Randy >> > -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 4054 bytes Desc: not available URL: From bruno.pagani at astrophysics.eu Wed May 22 14:40:07 2019 From: bruno.pagani at astrophysics.eu (Bruno Pagani) Date: Wed, 22 May 2019 20:40:07 +0200 Subject: [Matplotlib-users] Get color from legend for errorbar plots In-Reply-To: <096092ec-2b07-d2dd-defb-ac575ad0c3a0@astrophysics.eu> References: <096092ec-2b07-d2dd-defb-ac575ad0c3a0@astrophysics.eu> Message-ID: Le 22/05/2019 ? 20:34, Bruno Pagani a ?crit?: > Hi, > > I?ve stumbled upon this very exact issue, for which there is no posted > answer: > https://stackoverflow.com/questions/26573864/matplotlib-get-errorbar-color-from-legend > > Does anyone have an idea? > > Regards, > Bruno As a side note, I have a workaround that rely on issuing a subsequent plt.plot with the same data without errorbars, but if someone has a better solution? From bruno.pagani at astrophysics.eu Wed May 22 14:34:14 2019 From: bruno.pagani at astrophysics.eu (Bruno Pagani) Date: Wed, 22 May 2019 20:34:14 +0200 Subject: [Matplotlib-users] Get color from legend for errorbar plots Message-ID: <096092ec-2b07-d2dd-defb-ac575ad0c3a0@astrophysics.eu> Hi, I?ve stumbled upon this very exact issue, for which there is no posted answer: https://stackoverflow.com/questions/26573864/matplotlib-get-errorbar-color-from-legend Does anyone have an idea? Regards, Bruno From selasley at icloud.com Wed May 22 17:43:17 2019 From: selasley at icloud.com (Scott Lasley) Date: Wed, 22 May 2019 17:43:17 -0400 Subject: [Matplotlib-users] Get color from legend for errorbar plots In-Reply-To: <096092ec-2b07-d2dd-defb-ac575ad0c3a0@astrophysics.eu> References: <096092ec-2b07-d2dd-defb-ac575ad0c3a0@astrophysics.eu> Message-ID: As Tom Caswell pointed out, you can use the legendHandles. Something like this may do what you want plt.errorbar([1,2,3],[1,2,3],yerr=0.2,label='22') plt.errorbar([3,1,2],[2,3,1],yerr=0.3,label='33') z = plt.legend() [lc.get_colors() for lc in z.legendHandles] hth, Scott > On May 22, 2019, at 2:34 PM, Bruno Pagani wrote: > > Hi, > I?ve stumbled upon this very exact issue, for which there is no posted > answer: > https://stackoverflow.com/questions/26573864/matplotlib-get-errorbar-color-from-legend > Does anyone have an idea? > Regards, > Bruno From bruno.pagani at astrophysics.eu Thu May 23 06:34:25 2019 From: bruno.pagani at astrophysics.eu (Bruno Pagani) Date: Thu, 23 May 2019 12:34:25 +0200 Subject: [Matplotlib-users] Get color from legend for errorbar plots In-Reply-To: References: <096092ec-2b07-d2dd-defb-ac575ad0c3a0@astrophysics.eu> Message-ID: Le 22/05/2019 ? 23:43, Scott Lasley a ?crit?: > As Tom Caswell pointed out, you can use the legendHandles. Something like this may do what you want > > plt.errorbar([1,2,3],[1,2,3],yerr=0.2,label='22') > plt.errorbar([3,1,2],[2,3,1],yerr=0.3,label='33') > z = plt.legend() > [lc.get_colors() for lc in z.legendHandles] > > hth, > Scott Note that for some reason lc.get_colors() returns array of color in rgba format, e.g. [[r g b a]]. So I had to do lc.get_colors()[0] instead, but then it works fine. Thanks for your help, Bruno From pmhobson at gmail.com Thu May 23 09:28:20 2019 From: pmhobson at gmail.com (Paul Hobson) Date: Thu, 23 May 2019 06:28:20 -0700 Subject: [Matplotlib-users] Get color from legend for errorbar plots In-Reply-To: References: <096092ec-2b07-d2dd-defb-ac575ad0c3a0@astrophysics.eu> Message-ID: Hey Bruno, In this case, I believe `lc` is a LineCollection, so it's essentially a sequence of N lines. In this case, it appear N = 1. -p On Thu, May 23, 2019 at 3:34 AM Bruno Pagani wrote: > Le 22/05/2019 ? 23:43, Scott Lasley a ?crit : > > As Tom Caswell pointed out, you can use the legendHandles. Something > like this may do what you want > > > > plt.errorbar([1,2,3],[1,2,3],yerr=0.2,label='22') > > plt.errorbar([3,1,2],[2,3,1],yerr=0.3,label='33') > > z = plt.legend() > > [lc.get_colors() for lc in z.legendHandles] > > > > hth, > > Scott > > Note that for some reason lc.get_colors() returns array of color in rgba > format, e.g. [[r g b a]]. So I had to do lc.get_colors()[0] instead, but > then it works fine. > > Thanks for your help, > Bruno > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.pagani at astrophysics.eu Thu May 23 09:32:44 2019 From: bruno.pagani at astrophysics.eu (Bruno Pagani) Date: Thu, 23 May 2019 15:32:44 +0200 Subject: [Matplotlib-users] Get color from legend for errorbar plots In-Reply-To: References: <096092ec-2b07-d2dd-defb-ac575ad0c3a0@astrophysics.eu> Message-ID: <2cdd4725-e123-0bf3-5001-dab0efd43483@astrophysics.eu> Le 23/05/2019 ? 15:28, Paul Hobson a ?crit?: > Hey Bruno, > > In this case, I believe `lc` is a LineCollection, so it's essentially > a sequence of N lines. In this case, it appear N = 1. > -p Makes sense, thx. I?m posting an answer to the stackexchange question crediting all of you for your pointers. Regards, Bruno From tcaswell at gmail.com Sat May 25 21:11:22 2019 From: tcaswell at gmail.com (Thomas Caswell) Date: Sat, 25 May 2019 21:11:22 -0400 Subject: [Matplotlib-users] Autoscaling Date Locator with minor ticks? In-Reply-To: <20190504010908.GA9339@shallowsky.com> References: <20190504010908.GA9339@shallowsky.com> Message-ID: Akanna, Setting the minor and major locators in the correct approach, but you need to set them with different settings (as other wise they will decide to put the ticks at the sameplaces, hence the "doubled" labels. This behavior changed with 3.1 (see https://matplotlib.org/api/api_changes.html#major-minor-tick-collisions ) and going forward the overlapping minor ticks will be trimmed by default). I suspect that by playing with `minticks` and `maxticks` you can get the effect you want: import numpy as np import matplotlib.dates as mdates import matplotlib.pyplot as plt t = np.arange("2018-11-03", "2018-11-06", dtype="datetime64") x = np.random.rand(len(t)) fig, ax = plt.subplots() ax.plot(t, x) ax.xaxis.set( major_locator=mdates.AutoDateLocator(minticks=1, maxticks=5), minor_locator=mdates.AutoDateLocator(minticks=15, maxticks=52), ) plt.show() You may also be interested in the ConciseDateFormatter ( https://matplotlib.org/users/whats_new.html#concisedateformatter ) that is new in 3.1. Tom On Fri, May 3, 2019 at 9:16 PM Akkana Peck wrote: > Is there any way to get AutoDateLocator to handle minor ticks as > well as major ones? > > For instance, if I have a plot spanning a few days, I'd like to be > able to show the date as a label and major tick, but show minor > ticks for hours, or one minor tick every six hours, whatever is > sensible depending on the scale. Or on a plot spanning a few years, > show labels for each year, but with 12 minor ticks showing months. > It seems like AutoDateLocator only draws major ticks. > > I can write a custom date locator that handles the minor ticks > nicely, but then I don't get the nice auto-scaling of > AutoDateLocator, and if I plot a larger or smaller date range, > my labels and ticks become too crowded or too sparse. > > I tried setting both major and minor locators to AutoDateLocators: > ax.xaxis.set_major_locator(AutoDateLocator()) > ax.xaxis.set_minor_locator(AutoDateLocator()) > and similarly with set_*_formatter(), but that just gave me > smeary-looking double-printed major labels and ticks. > > Maybe I need to write a custom smart locator that reproduces > AutoDateLocator's auto-scaling while also handling ticks. But before > I dive into that, I thought I'd ask; I can't be the only person who > needs more precise ticks and labeling than AutoDateLocator provides. > > Thanks! > > ...Akkana > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -- Thomas Caswell tcaswell at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From pnsinha68 at gmail.com Fri May 31 05:07:26 2019 From: pnsinha68 at gmail.com (Partha Sinha) Date: Fri, 31 May 2019 14:37:26 +0530 Subject: [Matplotlib-users] plot Message-ID: I want help on graph I need to plot numbers one by one (lets say after interval of 5 sec) but all in the same graph. How to do ? My code is below import time import matplotlib.pyplot as plt import numpy as np from random import randint i = 1 numbers = [0]*5 while i < 5: numbers[i] = randint(0,100) plt.plot(np.arange(1,6),numbers, 'o') i += 1 matplotlib.pyplot.draw() time.sleep(5) -------------- next part -------------- An HTML attachment was scrubbed... URL: From selasley at icloud.com Fri May 31 11:40:53 2019 From: selasley at icloud.com (Scott Lasley) Date: Fri, 31 May 2019 11:40:53 -0400 Subject: [Matplotlib-users] plot In-Reply-To: References: Message-ID: <4295DD0C-4014-4C0D-B3CE-CFCD1D331D48@icloud.com> Try using plt.pause instead of time.sleep. This may do what you want import matplotlib.pyplot as plt from random import randint numbers = [0]*5 # draw the initial points oldlines = plt.plot(range(1, 6), numbers, 'o', c='r') plt.pause(5) for i in range(5): numbers[i] = randint(0,100) # remove the previously plotted lines before drawing the new ones oldlines[0].remove() oldlines = plt.plot(range(1, 6), numbers, 'o', c='r') plt.pause(5) > On May 31, 2019, at 5:07 AM, Partha Sinha wrote: > > I want help on graph > I need to plot numbers one by one (lets say after interval of 5 sec) but all in the same graph. How to do ? > My code is below > > > import time > import matplotlib.pyplot as plt > import numpy as np > from random import randint > i = 1 > numbers = [0]*5 > while i < 5: > numbers[i] = randint(0,100) > plt.plot(np.arange(1,6),numbers, 'o') > i += 1 > matplotlib.pyplot.draw() > time.sleep(5) > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users From pnsinha68 at gmail.com Fri May 31 12:11:27 2019 From: pnsinha68 at gmail.com (Partha Sinha) Date: Fri, 31 May 2019 21:41:27 +0530 Subject: [Matplotlib-users] plot In-Reply-To: <4295DD0C-4014-4C0D-B3CE-CFCD1D331D48@icloud.com> References: <4295DD0C-4014-4C0D-B3CE-CFCD1D331D48@icloud.com> Message-ID: It worked. However, I was looking for in one graph but here it's producing n no of graphs. can we make it in the graph ? partha On Fri, 31 May 2019 at 21:10, Scott Lasley wrote: > Try using plt.pause instead of time.sleep. This may do what you want > > import matplotlib.pyplot as plt > from random import randint > > numbers = [0]*5 > # draw the initial points > oldlines = plt.plot(range(1, 6), numbers, 'o', c='r') > plt.pause(5) > for i in range(5): > numbers[i] = randint(0,100) > # remove the previously plotted lines before drawing the new ones > oldlines[0].remove() > oldlines = plt.plot(range(1, 6), numbers, 'o', c='r') > plt.pause(5) > > > > > On May 31, 2019, at 5:07 AM, Partha Sinha wrote: > > > > I want help on graph > > I need to plot numbers one by one (lets say after interval of 5 sec) but > all in the same graph. How to do ? > > My code is below > > > > > > import time > > import matplotlib.pyplot as plt > > import numpy as np > > from random import randint > > i = 1 > > numbers = [0]*5 > > while i < 5: > > numbers[i] = randint(0,100) > > plt.plot(np.arange(1,6),numbers, 'o') > > i += 1 > > matplotlib.pyplot.draw() > > time.sleep(5) > > _______________________________________________ > > Matplotlib-users mailing list > > Matplotlib-users at python.org > > https://mail.python.org/mailman/listinfo/matplotlib-users > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From selasley at icloud.com Fri May 31 18:34:41 2019 From: selasley at icloud.com (Scott Lasley) Date: Fri, 31 May 2019 18:34:41 -0400 Subject: [Matplotlib-users] plot In-Reply-To: References: <4295DD0C-4014-4C0D-B3CE-CFCD1D331D48@icloud.com> Message-ID: Are you making the plots in a jupyter notebook? The code worked for me in ipython and when saved as a file and run from the command line, but it does produce multiple plots in a jupyter notebook. plt.pause does not seem to work in a notebook. The documentation for plt.pause says "This can be used for crude animation. For more complex animation, see matplotlib.animation." The snippet below is based on the matplotlib simple animation example (https://matplotlib.org/examples/animation/basic_example.html) It works in a jupyter notebook if you use the magic %matplotlib notebook or %matplotlib nbagg but it does not work in jupyter lab since those magics are not supported. %matplotlib nbagg import numpy as np from matplotlib import pyplot as plt from matplotlib.animation import FuncAnimation def draw_pts(i): y[i] = np.random.randint(10, 100) pts.set_data(x, y) ax.relim() ax.autoscale_view(scaley=True) return [pts] def init_pts(): return [] x = np.arange(1, 6) # set y to nan's so no points are drawn initially y = np.full(5, np.nan) fig, ax = plt.subplots() ax.set(xlim=[0, 6]) pts = ax.plot(x, y, 'o')[0] anim = FuncAnimation(fig, draw_pts, frames=5, init_func=init_pts, interval=2000, blit=True, repeat=False) Notes: If init_func is not set, draw_pts is called twice with i = 0, so I used a dummy init_pts function. ax.autoscale_view works in the jyputer notebook but the y axis does not update properly if the code is run in ipython on my mac. If repeat=True, draw_pts will be called forever with i ranging from 0 to frames - 1 repeatedly. interval sets the delay between updates in milliseconds. hth, Scott > On May 31, 2019, at 12:11 PM, Partha Sinha wrote: > > It worked. However, I was looking for in one graph but here it's producing n no of graphs. can we make it in the graph ? > partha > > > On Fri, 31 May 2019 at 21:10, Scott Lasley wrote: > Try using plt.pause instead of time.sleep. This may do what you want > > import matplotlib.pyplot as plt > from random import randint > > numbers = [0]*5 > # draw the initial points > oldlines = plt.plot(range(1, 6), numbers, 'o', c='r') > plt.pause(5) > for i in range(5): > numbers[i] = randint(0,100) > # remove the previously plotted lines before drawing the new ones > oldlines[0].remove() > oldlines = plt.plot(range(1, 6), numbers, 'o', c='r') > plt.pause(5) > > > > > On May 31, 2019, at 5:07 AM, Partha Sinha wrote: > > > > I want help on graph > > I need to plot numbers one by one (lets say after interval of 5 sec) but all in the same graph. How to do ? > > My code is below > > > > > > import time > > import matplotlib.pyplot as plt > > import numpy as np > > from random import randint > > i = 1 > > numbers = [0]*5 > > while i < 5: > > numbers[i] = randint(0,100) > > plt.plot(np.arange(1,6),numbers, 'o') > > i += 1 > > matplotlib.pyplot.draw() > > time.sleep(5) > > _______________________________________________ > > Matplotlib-users mailing list > > Matplotlib-users at python.org > > https://mail.python.org/mailman/listinfo/matplotlib-users > From rached.zakhama at 3-5lab.fr Wed May 29 10:43:58 2019 From: rached.zakhama at 3-5lab.fr (Rached Zakhama) Date: Wed, 29 May 2019 14:43:58 -0000 Subject: [Matplotlib-users] live plot Message-ID: <28dfeee6-6e5f-b369-a770-d2e6782f4a03@3-5lab.fr> Hi, I was trying to make a live plot with tkinter where I can see the data updating live in a for loop. I used a tkinter window to plot the matplotlib figure and I added a button. The problem is that I can't make the button work during the for loop. My example is : ############################## # imports import numpy as np from time import sleep import matplotlib matplotlib.use("TkAgg") from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg from matplotlib.figure import Figure from matplotlib.pyplot import pause import tkinter as tk fenetre = tk.Tk() # update function , called whenever the user hit the button : changes the plot line color def update(): ??? n=np.random.randint(4) ??? colors=['b','g','r','c'] ??? l.set_color(colors[n]) ??? canvas.show() # tkinter button, changes the line color bouton = tk.Button(fenetre, text="change color", command=update) bouton.pack() # create random data x=np.array([i for i in range(10)]) y=np.random.randn(10) # create matplotlib figure and plot fig=Figure(figsize=(5,5)) ax=fig.add_subplot(111) l,=ax.plot(x,y) # put the figure in the tkinter window canvas=FigureCanvasTkAgg(fig,fenetre) canvas.show() canvas.get_tk_widget().pack(side=tk.TOP,fill=tk.BOTH, expand=True) # add the toolbar toolbar= NavigationToolbar2TkAgg(canvas,fenetre) toolbar.update() canvas._tkcanvas.pack(side=tk.TOP,fill=tk.BOTH, expand=True) # update random data every? 2 seconds for i in range(15): ??? sleep(2) ??? y=np.random.randn(10) ??? l.set_ydata(y) ??? canvas.show() tk.mainloop() ###################### I am trying to see a plot random data changing on the screen every 2 seconds and change its color whenever I hit the button. It doesn't work since apparently Python? doesn't execute the button command before finishing the loop. Do you have any suggestions. Waiting hopefully for your replay. Best regards. ___________________________________________________________________ Rached ZAKHAMA Bureau 2B1 33 Thales Research & Technology III-V lab, 91120 Palaiseau,France tel: +33(0)169416021 ?+33(0)658787715 ___________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From lucasmigueel at gmail.com Wed May 1 12:19:39 2019 From: lucasmigueel at gmail.com (Lucas Carvalho) Date: Wed, 01 May 2019 16:19:39 -0000 Subject: [Matplotlib-users] Help with 3D math drawings Message-ID: Hello, My name is Lucas and I am a technical teacher in Brazil. A group of my high school students are using the matplotlib library to make 3D-plots but we are having problems drawing a cutting plane into a cone, for example. There are even other ideas, such as generating the solid resulting from the cutting of a sphere by a plane passing through its center or in any other position. Would be possible to help us? Thank you. Regards, -- Lucas Miguel de Carvalho PhD in Bioinformatics (UNICAMP - SP - Brazil) -------------- next part -------------- An HTML attachment was scrubbed... URL: