From sabvs647 at gmail.com Sun Apr 1 18:08:58 2018 From: sabvs647 at gmail.com (Sab VS) Date: Sun, 1 Apr 2018 18:08:58 -0400 Subject: [Matplotlib-users] Zooming in on Image data plotted using matplotlib Message-ID: Hi, I am trying to oom in on the image data plotted in 2 subplots using matplotlib. However, the zooming in needs to take into consideration both the images which are being displayed in the subplot. If I have 2 images on the subplot, I can click any one of these images. I then get the x and y coordinates. But I am not sure how to open a new window with the clicked coordinates and 5 or 10 pixels around the clicked coordinates and display it in a new window. Could someone please help me out? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben.v.root at gmail.com Mon Apr 2 22:17:51 2018 From: ben.v.root at gmail.com (Benjamin Root) Date: Mon, 2 Apr 2018 22:17:51 -0400 Subject: [Matplotlib-users] Zooming in on Image data plotted using matplotlib In-Reply-To: References: Message-ID: You can't get that feature out-of-the-box, but it is possible to construct such a feature with some work. You can create callbacks functions that take x/y coordinates to create a new figure window with remade imshow()'s. You might want to consider picking up a copy of my book, "Interactive Applications using Matplotlib", particularly focusing on chapter 2 on the callback system. I hope that helps! Ben Root On Sun, Apr 1, 2018 at 6:08 PM, Sab VS wrote: > Hi, > > I am trying to oom in on the image data plotted in 2 subplots using > matplotlib. However, the zooming in needs to take into consideration both > the images which are being displayed in the subplot. If I have 2 images on > the subplot, I can click any one of these images. I then get the x and y > coordinates. But I am not sure how to open a new window with the clicked > coordinates and 5 or 10 pixels around the clicked coordinates and display > it in a new window. > > Could someone please help me out? > > _______________________________________________ > 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 jni.soma at gmail.com Tue Apr 3 09:56:15 2018 From: jni.soma at gmail.com (Juan Nunez-Iglesias) Date: Tue, 03 Apr 2018 23:56:15 +1000 Subject: [Matplotlib-users] Zooming in on Image data plotted using matplotlib In-Reply-To: References: Message-ID: <1522763775.2204913.1324915216.0EB1AEA5@webmail.messagingengine.com> I want to second Ben's email: I highly recommend his book. I fumbled around for a long time with minor interactive matplotlib features. Then I read his book and it completely clarified my mental model of mpl interactivity and, indeed, of GUIs in general. Thanks Ben! Here's an excerpt that describes my situation quite well: """ Indeed, given that the primary audience for Matplotlib is scientific programmersfor whom GUIs are, at best, an afterthought, Matplotlib provides a gradual curveto create full-fledged GUI applications. For simple GUI tasks, one can go quite far with Matplotlib without ever having to adopt a GUI platform. And, as we will see in the next chapter, taking those final steps into a GUI application would not require getting rid of any existing code.""" Juan. On Tue, Apr 3, 2018, at 12:17 PM, Benjamin Root wrote: > You can't get that feature out-of-the-box, but it is possible to > construct such a feature with some work. You can create callbacks > functions that take x/y coordinates to create a new figure window with > remade imshow()'s. You might want to consider picking up a copy of my > book, "Interactive Applications using Matplotlib", particularly > focusing on chapter 2 on the callback system.> I hope that helps! > Ben Root > > On Sun, Apr 1, 2018 at 6:08 PM, Sab VS wrote: >> Hi, >> I am trying to oom in on the image data plotted in 2 subplots using >> matplotlib. However, the zooming in needs to take into consideration >> both the images which are being displayed in the subplot. If I have 2 >> images on the subplot, I can click any one of these images. I then >> get the x and y coordinates. But I am not sure how to open a new >> window with the clicked coordinates and 5 or 10 pixels around the >> clicked coordinates and display it in a new window.>> >> Could someone please help me out? >> >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users at python.org >> https://mail.python.org/mailman/listinfo/matplotlib-users >> > _________________________________________________ > 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 mathoscope at netcourrier.com Fri Apr 6 00:29:46 2018 From: mathoscope at netcourrier.com (Vincent Douce Mathoscope) Date: Fri, 6 Apr 2018 06:29:46 +0200 Subject: [Matplotlib-users] some problems In-Reply-To: References: Message-ID: hi i am workind on the thread "filling" since a cuple of months i did not use Matplotlib i have difficulties to get comfortable with simple lines of code for example (end of this mail) - why do the circle appear so big whereas the dimension of the picture are [0,5] for x and for y and the radius of the circle is 0.05 ? - why, if i cancel the paragraph named "oeil......", do the circle disappear ? thanks for your help... figur generated : lines of code : ----- import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl # quelques param?tres par d?faut plt.style.use('bmh') mpl.rcParams['font.family'] = 'STIXGeneral' plt.rcParams["font.size"] = 10 # dimensions ? choisir xmin,xmax,ymin,ymax=0,5,0,5 (L,l)=(7,7) # fenetrages divers Linch,linch=(L/2.54,l/2.54) fig, lafigure = plt.subplots(figsize=(Linch,linch)) Lx,x,Ly,y=[],xmin,[],ymin while (x<=xmax): Lx.append(x) x+=1 while (y<=ymax): Ly.append(y) y+=1 #oeil............. X1 = np.linspace(1-np.sqrt(2),1+np.sqrt(2), 256,endpoint=True) Y1 = np.sqrt(2-X1**2) lafigure.plot(X1, Y1, color="black", linewidth=0.5, linestyle="-") lafigure.plot(X1, 1-Y1, color="black", linewidth=0.5, linestyle="-") # trac? d'un cercle r=0.05 lafigure.add_patch(mpl.patches.Circle((r, r),1,color ='black', linewidth=0.5, fill=False,linestyle="--")) plt.axis('off') lafigure.spines['right'].set_visible(True) plt.show() -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PastedGraphic-7.png Type: image/png Size: 42418 bytes Desc: not available URL: From jerzy.karczmarczuk at unicaen.fr Fri Apr 6 04:01:19 2018 From: jerzy.karczmarczuk at unicaen.fr (Jerzy Karczmarczuk) Date: Fri, 6 Apr 2018 10:01:19 +0200 Subject: [Matplotlib-users] some problems In-Reply-To: References: Message-ID: <1b3af55a-fed0-5a53-d7f4-5a4ce9b5d7e1@unicaen.fr> Le 06/04/2018 ? 06:29, Vincent Douce Mathoscope a ?crit?: > hi > i am workind on the thread "filling" > since a cuple of months i did not use Matplotlib > i have difficulties to get comfortable with simple lines of code > for example (end of this mail) > - why do the circle appear so big whereas the dimension of the picture > are [0,5] for x and for y and the radius of the circle is 0.05 ? * The dimensions of your *figure*? are of 2.75 inches (7/2.54). * [0, 5] for xmin, xmax etc. are your conventional units within axes, not related to figsize. * The radius of your Circle patch is 1 ; ?? (0.05,0.05) is its center. > - why, if i cancel the paragraph named "oeil......", do the circle > disappear ? > * I don't see any disappearance. If you "close your eye", the two plots of sqrt(whatever) are eliminated,, but the patch is still there. Only Matplotlib redefines the scale of the plot, the circle becomes bigger, and a smaller fragment is plotted. Notice that you never fix the scales using axis(...). Bon courage. Jerzy Karczmarczuk /Caen/ From vincent.adrien at gmail.com Fri Apr 6 14:07:05 2018 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Fri, 6 Apr 2018 11:07:05 -0700 Subject: [Matplotlib-users] some problems In-Reply-To: <1b3af55a-fed0-5a53-d7f4-5a4ce9b5d7e1@unicaen.fr> References: <1b3af55a-fed0-5a53-d7f4-5a4ce9b5d7e1@unicaen.fr> Message-ID: <5f0edb6d-05fb-0b55-aa73-cf209aa485d7@gmail.com> Hi Vincent, I think that Jerzy got the correct answer about your issue with the circle patch. The docstrings reads indeed: ``` mpl.patches.Circle(xy, radius=5, **kwargs) Create true circle at center *xy* = (*x*, *y*) with given *radius*. ``` I did not notice any disappearance when commenting the "oeil" section either :/. (Attached is a script based on yours that gives the attached PNG.) Best regards, Adrien On 04/06/2018 01:01 AM, Jerzy Karczmarczuk wrote: > > > Le 06/04/2018 ? 06:29, Vincent Douce Mathoscope a ?crit?: >> hi >> i am workind on the thread "filling" >> since a cuple of months i did not use Matplotlib >> i have difficulties to get comfortable with simple lines of code >> for example (end of this mail) >> - why do the circle appear so big whereas the dimension of the picture >> are [0,5] for x and for y and the radius of the circle is 0.05 ? > * The dimensions of your *figure*? are of 2.75 inches (7/2.54). > * [0, 5] for xmin, xmax etc. are your conventional units within axes, > not related to figsize. > * The radius of your Circle patch is 1 ; ?? (0.05,0.05) is its center. > >> - why, if i cancel the paragraph named "oeil......", do the circle >> disappear ? >> > * I don't see any disappearance. If you "close your eye", the two plots > of sqrt(whatever) are eliminated,, but the patch is still there. Only > Matplotlib redefines the scale of the plot, the circle becomes bigger, > and a smaller fragment is plotted. > Notice that you never fix the scales using axis(...). > > Bon courage. > > Jerzy Karczmarczuk > /Caen/ > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users -------------- next part -------------- A non-text attachment was scrubbed... Name: exemple_cercle.py Type: text/x-python Size: 2356 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: exemple_cercle.png Type: image/png Size: 9197 bytes Desc: not available URL: From rhkubiak at gmail.com Mon Apr 9 13:34:38 2018 From: rhkubiak at gmail.com (Ryszard Kubiak) Date: Mon, 9 Apr 2018 19:34:38 +0200 Subject: [Matplotlib-users] Can't place text nest to another one Message-ID: Hello everybody, Please, take a look at the code below. I want to place the text 'xyz' just next to 'abc'. The reusult is that 'xyz' goes much further right to 'abc' and there is a gap between the texts. The width of the bbox happens to be 40, as the printout shows. The 'xyz' text is indeed at 40. However, one can see on the canvas that 'abc' width is only about 6.5. Thus, there is a mismatch between what get_window_extent calculates (40) and what the text size is on the canvas (6.5). What am I doing wrong? Best Regards, Ryszard import matplotlib.pyplot as plt fig = plt.figure(frameon=False) ax = plt.Axes(fig, [0.0, 0.0, 1.0, 1.0]) ax.set_axis_off() ax.set_xlim(0, 100) ax.set_ylim(0, 100) fig.add_axes(ax) renderer = fig.canvas.get_renderer() abc = plt.text(0, 0, 'abc', fontsize=20, bbox=dict(facecolor='red', alpha=0.2, pad=0)) bbox = abc.get_window_extent(renderer=renderer) print('width:', bbox.width, 'height:', bbox.height) xyz = plt.text(bbox.width, 0, 'xyz', fontsize=20, bbox=dict(facecolor='blue', alpha=0.2, pad=0)) plt.show() From tcaswell at gmail.com Tue Apr 10 20:16:01 2018 From: tcaswell at gmail.com (Thomas Caswell) Date: Wed, 11 Apr 2018 00:16:01 +0000 Subject: [Matplotlib-users] John Hunter Matplotlib Summer Fellowship 2018 Message-ID: Folks, We are happy to announce that we will be supporting a summer student to work on Matplotlib this summer! The student will be writing a Matplotlib based renderer for Altair and primarily mentored by Hannah. Altair is a declarative statistical visualization library for Python, based on Vega and Vega-Lite. Currently Altair charts can only be rendered in the browser, so we are looking for a student to write a Matplotlib based renderer for Altair. This renderer would take in Altair objects and produce Matplotlib objects for integration with existing tools and to generate publication-quality figures. To apply, please submit a cover letter and resume/CV to matplotlib at numfocus.org by May 4, 2018. https://www.numfocus.org/programs/john-hunter-technology-fellowship for more details. Please distribute this to your networks! Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From tcaswell at gmail.com Fri Apr 13 15:10:11 2018 From: tcaswell at gmail.com (Thomas Caswell) Date: Fri, 13 Apr 2018 19:10:11 +0000 Subject: [Matplotlib-users] Can't place text nest to another one In-Reply-To: References: Message-ID: The problem is that we do not know how big the text will be until we actually render it so `abc.get_window_extent` is lying. I suggest looking at https://matplotlib.org/tutorials/text/annotations.html#using-complex-coordinates-with-annotations which shows how to defer the calling of `get_window_extent` until as late as possible. Tom On Mon, Apr 9, 2018 at 1:35 PM Ryszard Kubiak wrote: > Hello everybody, > > Please, take a look at the code below. I want to place the text 'xyz' > just next to 'abc'. The reusult is that 'xyz' goes much further right to > 'abc' and there is a gap between the texts. > > The width of the bbox happens to be 40, as the printout shows. The 'xyz' > text is indeed at 40. However, one can see on the canvas that 'abc' > width is only about 6.5. Thus, there is a mismatch between what > get_window_extent calculates (40) and what the text size is on the > canvas (6.5). > > What am I doing wrong? > > Best Regards, > Ryszard > > import matplotlib.pyplot as plt > > fig = plt.figure(frameon=False) > ax = plt.Axes(fig, [0.0, 0.0, 1.0, 1.0]) > ax.set_axis_off() > ax.set_xlim(0, 100) > ax.set_ylim(0, 100) > fig.add_axes(ax) > renderer = fig.canvas.get_renderer() > abc = plt.text(0, 0, 'abc', fontsize=20, bbox=dict(facecolor='red', > alpha=0.2, pad=0)) > bbox = abc.get_window_extent(renderer=renderer) > print('width:', bbox.width, 'height:', bbox.height) > xyz = plt.text(bbox.width, 0, 'xyz', fontsize=20, > bbox=dict(facecolor='blue', alpha=0.2, pad=0)) > plt.show() > > _______________________________________________ > 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 tcaswell at gmail.com Fri Apr 13 17:18:44 2018 From: tcaswell at gmail.com (Thomas Caswell) Date: Fri, 13 Apr 2018 21:18:44 +0000 Subject: [Matplotlib-users] Zooming in on Image data plotted using matplotlib In-Reply-To: <1522763775.2204913.1324915216.0EB1AEA5@webmail.messagingengine.com> References: <1522763775.2204913.1324915216.0EB1AEA5@webmail.messagingengine.com> Message-ID: Also see the examples in https://matplotlib.org/gallery/index.html#event-handling the event-handling section of the docs. Tom On Tue, Apr 3, 2018 at 9:56 AM Juan Nunez-Iglesias wrote: > I want to second Ben's email: I highly recommend his book. I fumbled > around for a long time with minor interactive matplotlib features. Then I > read his book and it completely clarified my mental model of mpl > interactivity and, indeed, of GUIs in general. Thanks Ben! > > Here's an excerpt that describes my situation quite well: > > """ > Indeed, given that the primary audience for Matplotlib is scientific > programmers > for whom GUIs are, at best, an afterthought, Matplotlib provides a gradual > curve > to create full-fledged GUI applications. For simple GUI tasks, one can go > quite far with Matplotlib without ever having to adopt a GUI platform. And, > as we will see in the next chapter, taking those final steps into a GUI > application would not require getting rid of any existing code. > """ > > Juan. > > On Tue, Apr 3, 2018, at 12:17 PM, Benjamin Root wrote: > > You can't get that feature out-of-the-box, but it is possible to construct > such a feature with some work. You can create callbacks functions that take > x/y coordinates to create a new figure window with remade imshow()'s. You > might want to consider picking up a copy of my book, "Interactive > Applications using Matplotlib", particularly focusing on chapter 2 on the > callback system. > I hope that helps! > Ben Root > > On Sun, Apr 1, 2018 at 6:08 PM, Sab VS wrote: > > Hi, > I am trying to oom in on the image data plotted in 2 subplots using > matplotlib. However, the zooming in needs to take into consideration both > the images which are being displayed in the subplot. If I have 2 images on > the subplot, I can click any one of these images. I then get the x and y > coordinates. But I am not sure how to open a new window with the clicked > coordinates and 5 or 10 pixels around the clicked coordinates and display > it in a new window. > > Could someone please help me out? > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > > *_______________________________________________* > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > > > _______________________________________________ > 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 rhkubiak at gmail.com Sun Apr 15 16:21:06 2018 From: rhkubiak at gmail.com (Ryszard Kubiak) Date: Sun, 15 Apr 2018 22:21:06 +0200 Subject: [Matplotlib-users] Can't place text nest to another one In-Reply-To: References: Message-ID: <6ae3c979-da8d-ce4c-380a-d228e52dee59@gmail.com> Thank you, Thomas, for your reply. You are right that I have to use an appropriate transofrm to turn canvas points yielded by get_window_extent() to the actual Axes's coordinates. The transforms.offset_copy(...) function came to my rescue. Thanks again, Ryszard > The problem is that we do not know how big the text will be until we > actually render it so `abc.get_window_extent` is lying. > > I suggest looking at > https://matplotlib.org/tutorials/text/annotations.html#using-complex-coordinates-with-annotations?which > shows how to defer the calling of `get_window_extent` until as late as > possible. > > Tom > > On Mon, Apr 9, 2018 at 1:35 PM Ryszard Kubiak > wrote: > > Hello everybody, > > Please, take a look at the code below. I want to place the text 'xyz' > just next to 'abc'. The reusult is that 'xyz' goes much further > right to > 'abc' and there is a gap between the texts. > > The width of the bbox happens to be 40, as the printout shows. The > 'xyz' > text is indeed at 40. However, one can see on the canvas that 'abc' > width is only about 6.5. Thus, there is a mismatch between what > get_window_extent calculates (40) and what the text size is on the > canvas (6.5). > > What am I doing wrong? > > Best Regards, > Ryszard > > import matplotlib.pyplot as plt > > fig = plt.figure(frameon=False) > ax = plt.Axes(fig, [0.0, 0.0, 1.0, 1.0]) > ax.set_axis_off() > ax.set_xlim(0, 100) > ax.set_ylim(0, 100) > fig.add_axes(ax) > renderer = fig.canvas.get_renderer() > abc = plt.text(0, 0, 'abc', fontsize=20, bbox=dict(facecolor='red', > alpha=0.2, pad=0)) > bbox = abc.get_window_extent(renderer=renderer) > print('width:', bbox.width, 'height:', bbox.height) > xyz = plt.text(bbox.width, 0, 'xyz', fontsize=20, > bbox=dict(facecolor='blue', alpha=0.2, pad=0)) > plt.show() > > _______________________________________________ > 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 voodoo.bender at gmail.com Mon Apr 16 10:25:18 2018 From: voodoo.bender at gmail.com (alberto) Date: Mon, 16 Apr 2018 16:25:18 +0200 Subject: [Matplotlib-users] invert columns and labels Message-ID: Hi, I use this command to calculate an array of 3x3 matrices sigma = data[indices, 3:12].reshape((-1, 3, 3)) to return # Plot the xx, yy and zz components as a function of the first column plt.figure() labels = ("xx", "yy", "zz") for i, label in enumerate(labels): plt.plot(Ef, sigma[:, i, i], label=label) plt.legend(loc="best") plt.xlabel(r"Energy [eV]") plt.ylabel(r"$\sigma$ [1/$\Omega$ m s]") plt.tight_layout() plt.show() How could invert the results xx to zz? something as data[indices, 12:3]? regards Alberto -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent.adrien at gmail.com Mon Apr 16 11:50:52 2018 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Mon, 16 Apr 2018 08:50:52 -0700 Subject: [Matplotlib-users] invert columns and labels In-Reply-To: References: Message-ID: <4f2340ec-9901-0c9d-a825-4425f623e3e1@gmail.com> Hi Alberto, Without an small example of the arrays *data* and *indices* (as well as possibly *Ef*) or a more precise description of their shape and dimensions, I have to admit that it is a bit difficult (at least for me) to understand precisely what you are trying to plot and to invert. For what I understood, I wonder if you are not just looking for something like ``sigma[:, i, i][::-1]`` (more information on slicing here: https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html#basic-slicing-and-indexing), I may just have missed the point. Beware that you may also have to flip the *labels*. Best regards, Adrien On 04/16/2018 07:25 AM, alberto wrote: > Hi, > I use this command to calculate an array of 3x3 matrices > > sigma = data[indices, 3:12].reshape((-1, 3, 3)) > > to return > > # Plot the xx, yy and zz components as a function of the first column > plt.figure() > labels = ("xx", "yy", "zz") > for i, label in enumerate(labels): > ??? plt.plot(Ef, sigma[:, i, i], label=label) > plt.legend(loc="best") > plt.xlabel(r"Energy [eV]") > plt.ylabel(r"$\sigma$ [1/$\Omega$ m s]") > plt.tight_layout() > plt.show() > > > How could invert the results xx to zz? > > something as data[indices, 12:3]? > > regards > > Alberto > > > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > From vs at it.uu.se Tue Apr 17 10:12:07 2018 From: vs at it.uu.se (Virgil Stokes) Date: Tue, 17 Apr 2018 16:12:07 +0200 Subject: [Matplotlib-users] Axes array for subplots Message-ID: <43e5aa2d-f391-9f5f-a247-d080745df9c5@it.uu.se> The following line is part of a much larger python (3.6) with Matplotlib (2.2.2) program in which the number of subplots is determined from input data: fig, axarr = plt.subplots(NSub, figsize=(width,height), sharex=True) This works fine when the number of subplots (NSub) is greater than 1. For example when NSub=3, axarr is an array of length 3 and contains: array([, ???????? , ???????? ], ??????? dtype=object) However, when NSub=1, axarr contains: and of course, will give an error if axarr is an array; i.e. builtins.TypeError: 'AxesSubplot' object does not support indexing For my code this requires special handling because axarr is no longer an array. Why not have axarr contain: array([],dtype=object) when NSub=1. IMHO this is consistent; i.e. it is an array with a length that is equal to the number of subplots. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben.v.root at gmail.com Tue Apr 17 10:30:49 2018 From: ben.v.root at gmail.com (Benjamin Root) Date: Tue, 17 Apr 2018 10:30:49 -0400 Subject: [Matplotlib-users] Axes array for subplots In-Reply-To: <43e5aa2d-f391-9f5f-a247-d080745df9c5@it.uu.se> References: <43e5aa2d-f391-9f5f-a247-d080745df9c5@it.uu.se> Message-ID: By default, `squeeze` is called on the array prior to returning it. This way, users don't need to deal with 2D arrays when most of the time, they are dealing with 1D setups. You can specify squeeze=False to subplots to turn this behavior off and always have a 2D array. I hope that helps! Ben Root On Tue, Apr 17, 2018 at 10:12 AM, Virgil Stokes wrote: > The following line is part of a much larger python (3.6) with Matplotlib > (2.2.2) program in which the number of subplots is determined from input > data: > > fig, axarr = plt.subplots(NSub, figsize=(width,height), sharex=True) > > This works fine when the number of subplots (NSub) is greater than 1. For > example when NSub=3, axarr is an array of length 3 and contains: > > array([ 0x0000025900E9DDD8>, > 0x00000259011897F0>, > 0x00000259011C7128>], > dtype=object) > > However, when NSub=1, axarr contains: > > > > and of course, will give an error if axarr is an array; i.e. > > builtins.TypeError: 'AxesSubplot' object does not support indexing > > For my code this requires special handling because axarr is no longer an > array. Why not have axarr contain: > > array([ 0x00000161AB26AE80>],dtype=object) > > when NSub=1. IMHO this is consistent; i.e. it is an array with a length > that is equal to the number of subplots. > > _______________________________________________ > 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 vs at it.uu.se Tue Apr 17 11:14:28 2018 From: vs at it.uu.se (Virgil Stokes) Date: Tue, 17 Apr 2018 17:14:28 +0200 Subject: [Matplotlib-users] Axes array for subplots In-Reply-To: References: <43e5aa2d-f391-9f5f-a247-d080745df9c5@it.uu.se> Message-ID: <951bcfd1-e953-17e3-9350-caec6231ab00@it.uu.se> Ok Ben, I tried the following per your suggestion: fig, axarr = plt.subplots(NSub, figsize=(width,height), squeeze=False, sharex=True) but when the following is executed: ? ax.grid(True) I get the following error message: ? builtins.AttributeError: 'numpy.ndarray' object has no attribute 'grid' But, thanks for your help :-). On 2018-04-17 16:30, Benjamin Root wrote: > By default, `squeeze` is called on the array prior to returning it. > This way, users don't need to deal with 2D arrays when most of the > time, they are dealing with 1D setups. You can specify squeeze=False > to subplots to turn this behavior off and always have a 2D array. > > I hope that helps! > Ben Root > > > On Tue, Apr 17, 2018 at 10:12 AM, Virgil Stokes > wrote: > > The following line is part of a much larger python (3.6) with > Matplotlib (2.2.2) program in which the number of subplots is > determined from input data: > > fig, axarr = plt.subplots(NSub, figsize=(width,height), sharex=True) > > This works fine when the number of subplots (NSub) is greater than > 1. For example when NSub=3, axarr is an array of length 3 and > contains: > > array([ 0x0000025900E9DDD8>, > ???????? 0x00000259011897F0>, > ???????? 0x00000259011C7128>], > ??????? dtype=object) > > However, when NSub=1, axarr contains: > > > > and of course, will give an error if axarr is an array; i.e. > > builtins.TypeError: 'AxesSubplot' object does not support indexing > > For my code this requires special handling because axarr is no > longer an array. Why not have axarr contain: > > array([ 0x00000161AB26AE80>],dtype=object) > > when NSub=1. IMHO this is consistent; i.e. it is an array with a > length that is equal to the number of subplots. > > _______________________________________________ > 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 ben.v.root at gmail.com Tue Apr 17 11:22:10 2018 From: ben.v.root at gmail.com (Benjamin Root) Date: Tue, 17 Apr 2018 11:22:10 -0400 Subject: [Matplotlib-users] Axes array for subplots In-Reply-To: <951bcfd1-e953-17e3-9350-caec6231ab00@it.uu.se> References: <43e5aa2d-f391-9f5f-a247-d080745df9c5@it.uu.se> <951bcfd1-e953-17e3-9350-caec6231ab00@it.uu.se> Message-ID: Virgil, How did you get from `axarr` to `ax`? The error message suggests that you haven't fully indexed the result. Remember, with squeeze=False, `axarr` will be a 2-D array, requiring two indices. Ben On Tue, Apr 17, 2018 at 11:14 AM, Virgil Stokes wrote: > Ok Ben, > > I tried the following per your suggestion: > > fig, axarr = plt.subplots(NSub, figsize=(width,height), squeeze=False, > sharex=True) > > but when the following is executed: > > ax.grid(True) > > I get the following error message: > builtins.AttributeError: 'numpy.ndarray' object has no attribute 'grid' > > But, thanks for your help :-). > > On 2018-04-17 16:30, Benjamin Root wrote: > > By default, `squeeze` is called on the array prior to returning it. This > way, users don't need to deal with 2D arrays when most of the time, they > are dealing with 1D setups. You can specify squeeze=False to subplots to > turn this behavior off and always have a 2D array. > > I hope that helps! > Ben Root > > > On Tue, Apr 17, 2018 at 10:12 AM, Virgil Stokes wrote: > >> The following line is part of a much larger python (3.6) with Matplotlib >> (2.2.2) program in which the number of subplots is determined from input >> data: >> >> fig, axarr = plt.subplots(NSub, figsize=(width,height), sharex=True) >> >> This works fine when the number of subplots (NSub) is greater than 1. For >> example when NSub=3, axarr is an array of length 3 and contains: >> >> array([> 0x0000025900E9DDD8>, >> > 0x00000259011897F0>, >> > 0x00000259011C7128>], >> dtype=object) >> >> However, when NSub=1, axarr contains: >> >> >> >> and of course, will give an error if axarr is an array; i.e. >> >> builtins.TypeError: 'AxesSubplot' object does not support indexing >> >> For my code this requires special handling because axarr is no longer an >> array. Why not have axarr contain: >> >> array([> 0x00000161AB26AE80>],dtype=object) >> >> when NSub=1. IMHO this is consistent; i.e. it is an array with a length >> that is equal to the number of subplots. >> >> _______________________________________________ >> 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 jslavin at cfa.harvard.edu Tue Apr 17 11:33:36 2018 From: jslavin at cfa.harvard.edu (Slavin, Jonathan) Date: Tue, 17 Apr 2018 11:33:36 -0400 Subject: [Matplotlib-users] Axes array for subplots Message-ID: ?Virgil, What is ax in your example? When I do fig,axarr = plt.subplots(1,squeeze=False,sharex=True) I get axarr is an array of shape (1,1). An array does not have an attribute grid. Jon ? > > Date: Tue, 17 Apr 2018 17:14:28 +0200 > From: Virgil Stokes > To: Benjamin Root , > > Subject: Re: [Matplotlib-users] Axes array for subplots > Message-ID: <951bcfd1-e953-17e3-9350-caec6231ab00 at it.uu.se> > Content-Type: text/plain; charset="utf-8"; Format="flowed" > > Ok Ben, > > I tried the following per your suggestion: > > fig, axarr = plt.subplots(NSub, figsize=(width,height), squeeze=False, > sharex=True) > > but when the following is executed: > > ? ax.grid(True) > > I get the following error message: > ? builtins.AttributeError: 'numpy.ndarray' object has no attribute 'grid' > > But, thanks for your help :-). > > > On 2018-04-17 16:30, Benjamin Root wrote: > > By default, `squeeze` is called on the array prior to returning it. > > This way, users don't need to deal with 2D arrays when most of the > > time, they are dealing with 1D setups. You can specify squeeze=False > > to subplots to turn this behavior off and always have a 2D array. > > > > I hope that helps! > > Ben Root > > > > > > On Tue, Apr 17, 2018 at 10:12 AM, Virgil Stokes > > wrote: > > > > The following line is part of a much larger python (3.6) with > > Matplotlib (2.2.2) program in which the number of subplots is > > determined from input data: > > > > fig, axarr = plt.subplots(NSub, figsize=(width,height), sharex=True) > > > > This works fine when the number of subplots (NSub) is greater than > > 1. For example when NSub=3, axarr is an array of length 3 and > > contains: > > > > array([ > 0x0000025900E9DDD8>, > > ???????? > 0x00000259011897F0>, > > ???????? > 0x00000259011C7128>], > > ??????? dtype=object) > > > > However, when NSub=1, axarr contains: > > > > > > > > and of course, will give an error if axarr is an array; i.e. > > > > builtins.TypeError: 'AxesSubplot' object does not support indexing > > > > For my code this requires special handling because axarr is no > > longer an array. Why not have axarr contain: > > > > array([ > 0x00000161AB26AE80>],dtype=object) > > > > when NSub=1. IMHO this is consistent; i.e. it is an array with a > > length that is equal to the number of subplots. > > > > _______________________________________________ > > 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: attachments/20180417/ced451e1/attachment.html> > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > > > ------------------------------ > > End of Matplotlib-users Digest, Vol 33, Issue 10 > ************************************************ > -- ________________________________________________________ Jonathan D. Slavin Harvard-Smithsonian CfA jslavin at cfa.harvard.edu 60 Garden Street, MS 83 phone: (617) 496-7981 Cambridge, MA 02138-1516 cell: (781) 363-0035 USA ________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From vs at it.uu.se Tue Apr 17 14:26:30 2018 From: vs at it.uu.se (Virgil Stokes) Date: Tue, 17 Apr 2018 20:26:30 +0200 Subject: [Matplotlib-users] Axes array for subplots In-Reply-To: References: <43e5aa2d-f391-9f5f-a247-d080745df9c5@it.uu.se> <951bcfd1-e953-17e3-9350-caec6231ab00@it.uu.se> Message-ID: ax is used in a function that references axarr. My problem is not about 2D arrays. --V On 2018-04-17 17:22, Benjamin Root wrote: > Virgil, > > How did you get from `axarr` to `ax`? The error message suggests that > you haven't fully indexed the result. Remember, with squeeze=False, > `axarr` will be a 2-D array, requiring two indices. > > Ben > > On Tue, Apr 17, 2018 at 11:14 AM, Virgil Stokes > wrote: > > Ok Ben, > > I tried the following per your suggestion: > > fig, axarr = plt.subplots(NSub, figsize=(width,height), > squeeze=False, sharex=True) > > but when the following is executed: > > ? ax.grid(True) > > I get the following error message: > builtins.AttributeError: 'numpy.ndarray' object has no attribute > 'grid' > > But, thanks for your help :-). > > > On 2018-04-17 16:30, Benjamin Root wrote: >> By default, `squeeze` is called on the array prior to returning >> it. This way, users don't need to deal with 2D arrays when most >> of the time, they are dealing with 1D setups. You can specify >> squeeze=False to subplots to turn this behavior off and always >> have a 2D array. >> >> I hope that helps! >> Ben Root >> >> >> On Tue, Apr 17, 2018 at 10:12 AM, Virgil Stokes > > wrote: >> >> The following line is part of a much larger python (3.6) with >> Matplotlib (2.2.2) program in which the number of subplots is >> determined from input data: >> >> fig, axarr = plt.subplots(NSub, figsize=(width,height), >> sharex=True) >> >> This works fine when the number of subplots (NSub) is greater >> than 1. For example when NSub=3, axarr is an array of length >> 3 and contains: >> >> array([> 0x0000025900E9DDD8>, >> > 0x00000259011897F0>, >> > 0x00000259011C7128>], >> ??????? dtype=object) >> >> However, when NSub=1, axarr contains: >> >> > 0x00000161AB26AE80> >> >> and of course, will give an error if axarr is an array; i.e. >> >> builtins.TypeError: 'AxesSubplot' object does not support >> indexing >> >> For my code this requires special handling because axarr is >> no longer an array. Why not have axarr contain: >> >> array([> 0x00000161AB26AE80>],dtype=object) >> >> when NSub=1. IMHO this is consistent; i.e. it is an array >> with a length that is equal to the number of subplots. >> >> _______________________________________________ >> 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 ben.v.root at gmail.com Tue Apr 17 14:43:37 2018 From: ben.v.root at gmail.com (Benjamin Root) Date: Tue, 17 Apr 2018 14:43:37 -0400 Subject: [Matplotlib-users] Axes array for subplots In-Reply-To: References: <43e5aa2d-f391-9f5f-a247-d080745df9c5@it.uu.se> <951bcfd1-e953-17e3-9350-caec6231ab00@it.uu.se> Message-ID: Virgil, I will be very specific: The following all references the copy of Plotting_Test03.py you sent me. At line 263, you have a comment: "# The Axes array (axarr) will be a list of NSub objects (an axis for each subplot)". This is incorrect. `axarr` is not a list, but a numpy array *or scalar*. When plt.subplots(1) is called, you get a numpy scalar, which is the problem that you originally approached us about. When plt.subplots(2) is called, you get a 1D numpy array, which looks a lot like a list. However, if plt.subplots(2, squeeze=False) is called, then you get a *2D* numpy array of axes, of shape (2, 1). That is because plt.subplots(), in the general case, is used for specifying the number of rows and columns of subplots, so without squeezing, the axes array is 2D. Therefore, if you have squeeze=False turned on in plt.subplots(), then line 306 needs to change to `ax = axarr[j, 0]`. Similar to line 318, and the area around line 331. Ben Root On Tue, Apr 17, 2018 at 2:26 PM, Virgil Stokes wrote: > ax is used in a function that references axarr. My problem is not about 2D > arrays. > > --V > > On 2018-04-17 17:22, Benjamin Root wrote: > > Virgil, > > How did you get from `axarr` to `ax`? The error message suggests that you > haven't fully indexed the result. Remember, with squeeze=False, `axarr` > will be a 2-D array, requiring two indices. > > Ben > > On Tue, Apr 17, 2018 at 11:14 AM, Virgil Stokes wrote: > >> Ok Ben, >> >> I tried the following per your suggestion: >> >> fig, axarr = plt.subplots(NSub, figsize=(width,height), squeeze=False, >> sharex=True) >> >> but when the following is executed: >> >> ax.grid(True) >> >> I get the following error message: >> builtins.AttributeError: 'numpy.ndarray' object has no attribute 'grid' >> >> But, thanks for your help :-). >> >> On 2018-04-17 16:30, Benjamin Root wrote: >> >> By default, `squeeze` is called on the array prior to returning it. This >> way, users don't need to deal with 2D arrays when most of the time, they >> are dealing with 1D setups. You can specify squeeze=False to subplots to >> turn this behavior off and always have a 2D array. >> >> I hope that helps! >> Ben Root >> >> >> On Tue, Apr 17, 2018 at 10:12 AM, Virgil Stokes wrote: >> >>> The following line is part of a much larger python (3.6) with Matplotlib >>> (2.2.2) program in which the number of subplots is determined from input >>> data: >>> >>> fig, axarr = plt.subplots(NSub, figsize=(width,height), sharex=True) >>> >>> This works fine when the number of subplots (NSub) is greater than 1. >>> For example when NSub=3, axarr is an array of length 3 and contains: >>> >>> array([>> 0x0000025900E9DDD8>, >>> >> 0x00000259011897F0>, >>> >> 0x00000259011C7128>], >>> dtype=object) >>> >>> However, when NSub=1, axarr contains: >>> >>> >>> >>> and of course, will give an error if axarr is an array; i.e. >>> >>> builtins.TypeError: 'AxesSubplot' object does not support indexing >>> >>> For my code this requires special handling because axarr is no longer an >>> array. Why not have axarr contain: >>> >>> array([>> 0x00000161AB26AE80>],dtype=object) >>> >>> when NSub=1. IMHO this is consistent; i.e. it is an array with a length >>> that is equal to the number of subplots. >>> >>> _______________________________________________ >>> 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 vincent.adrien at gmail.com Tue Apr 17 14:55:26 2018 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Tue, 17 Apr 2018 11:55:26 -0700 Subject: [Matplotlib-users] Axes array for subplots In-Reply-To: References: <43e5aa2d-f391-9f5f-a247-d080745df9c5@it.uu.se> <951bcfd1-e953-17e3-9350-caec6231ab00@it.uu.se> Message-ID: Hi Virgil, I suspect that should you are using something like ``` ax = axarr[i] ``` while `squeeze=False` will require that you use ``` ax = axarr[i, 0] ``` (from what I understood from you example). Please find attached a code snippet that should hopefully better demonstrate this. Best regards, Adrien On 04/17/2018 11:26 AM, Virgil Stokes wrote: > ax is used in a function that references axarr. My problem is not about > 2D arrays. > > --V > > > On 2018-04-17 17:22, Benjamin Root wrote: >> Virgil, >> >> How did you get from `axarr` to `ax`? The error message suggests that >> you haven't fully indexed the result. Remember, with squeeze=False, >> `axarr` will be a 2-D array, requiring two indices. >> >> Ben >> >> On Tue, Apr 17, 2018 at 11:14 AM, Virgil Stokes > > wrote: >> >> Ok Ben, >> >> I tried the following per your suggestion: >> >> fig, axarr = plt.subplots(NSub, figsize=(width,height), >> squeeze=False, sharex=True) >> >> but when the following is executed: >> >> ? ax.grid(True) >> >> I get the following error message: >> builtins.AttributeError: 'numpy.ndarray' object has no attribute >> 'grid' >> >> But, thanks for your help :-). >> >> >> On 2018-04-17 16:30, Benjamin Root wrote: >>> By default, `squeeze` is called on the array prior to returning >>> it. This way, users don't need to deal with 2D arrays when most >>> of the time, they are dealing with 1D setups. You can specify >>> squeeze=False to subplots to turn this behavior off and always >>> have a 2D array. >>> >>> I hope that helps! >>> Ben Root >>> >>> >>> On Tue, Apr 17, 2018 at 10:12 AM, Virgil Stokes >> > wrote: >>> >>> The following line is part of a much larger python (3.6) with >>> Matplotlib (2.2.2) program in which the number of subplots is >>> determined from input data: >>> >>> fig, axarr = plt.subplots(NSub, figsize=(width,height), >>> sharex=True) >>> >>> This works fine when the number of subplots (NSub) is greater >>> than 1. For example when NSub=3, axarr is an array of length >>> 3 and contains: >>> >>> array([>> 0x0000025900E9DDD8>, >>> >> 0x00000259011897F0>, >>> >> 0x00000259011C7128>], >>> ??????? dtype=object) >>> >>> However, when NSub=1, axarr contains: >>> >>> >> 0x00000161AB26AE80> >>> >>> and of course, will give an error if axarr is an array; i.e. >>> >>> builtins.TypeError: 'AxesSubplot' object does not support >>> indexing >>> >>> For my code this requires special handling because axarr is >>> no longer an array. Why not have axarr contain: >>> >>> array([>> 0x00000161AB26AE80>],dtype=object) >>> >>> when NSub=1. IMHO this is consistent; i.e. it is an array >>> with a length that is equal to the number of subplots. >>> >>> _______________________________________________ >>> Matplotlib-users mailing list >>> Matplotlib-users at python.org >>> https://mail.python.org/mailman/listinfo/matplotlib-users >>> >>> >>> >> >> > > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- A non-text attachment was scrubbed... Name: example_virgil.py Type: text/x-python Size: 859 bytes Desc: not available URL: From sabvs647 at gmail.com Wed Apr 18 00:47:36 2018 From: sabvs647 at gmail.com (Sab VS) Date: Wed, 18 Apr 2018 00:47:36 -0400 Subject: [Matplotlib-users] Zooming in on Image data plotted using matplotlib In-Reply-To: References: <1522763775.2204913.1324915216.0EB1AEA5@webmail.messagingengine.com> Message-ID: Thnaks for the help. On Fri, Apr 13, 2018 at 5:18 PM, Thomas Caswell wrote: > Also see the examples in https://matplotlib.org/gallery/index.html#event- > handling the event-handling section of the docs. > > Tom > > On Tue, Apr 3, 2018 at 9:56 AM Juan Nunez-Iglesias > wrote: > >> I want to second Ben's email: I highly recommend his book. I fumbled >> around for a long time with minor interactive matplotlib features. Then I >> read his book and it completely clarified my mental model of mpl >> interactivity and, indeed, of GUIs in general. Thanks Ben! >> >> Here's an excerpt that describes my situation quite well: >> >> """ >> Indeed, given that the primary audience for Matplotlib is scientific >> programmers >> for whom GUIs are, at best, an afterthought, Matplotlib provides a >> gradual curve >> to create full-fledged GUI applications. For simple GUI tasks, one can go >> quite far with Matplotlib without ever having to adopt a GUI platform. And, >> as we will see in the next chapter, taking those final steps into a GUI >> application would not require getting rid of any existing code. >> """ >> >> Juan. >> >> On Tue, Apr 3, 2018, at 12:17 PM, Benjamin Root wrote: >> >> You can't get that feature out-of-the-box, but it is possible to >> construct such a feature with some work. You can create callbacks functions >> that take x/y coordinates to create a new figure window with remade >> imshow()'s. You might want to consider picking up a copy of my book, >> "Interactive Applications using Matplotlib", particularly focusing on >> chapter 2 on the callback system. >> I hope that helps! >> Ben Root >> >> On Sun, Apr 1, 2018 at 6:08 PM, Sab VS wrote: >> >> Hi, >> I am trying to oom in on the image data plotted in 2 subplots using >> matplotlib. However, the zooming in needs to take into consideration both >> the images which are being displayed in the subplot. If I have 2 images on >> the subplot, I can click any one of these images. I then get the x and y >> coordinates. But I am not sure how to open a new window with the clicked >> coordinates and 5 or 10 pixels around the clicked coordinates and display >> it in a new window. >> >> Could someone please help me out? >> >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users at python.org >> https://mail.python.org/mailman/listinfo/matplotlib-users >> >> *_______________________________________________* >> Matplotlib-users mailing list >> Matplotlib-users at python.org >> https://mail.python.org/mailman/listinfo/matplotlib-users >> >> >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users at python.org >> https://mail.python.org/mailman/listinfo/matplotlib-users >> > > _______________________________________________ > 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 tcaswell at gmail.com Fri Apr 20 13:49:19 2018 From: tcaswell at gmail.com (Thomas Caswell) Date: Fri, 20 Apr 2018 17:49:19 +0000 Subject: [Matplotlib-users] Callback mechanism for animation completed? In-Reply-To: <5A062020-F99A-47F5-9A8E-9D48EAD01A1E@deitel.com> References: <5A062020-F99A-47F5-9A8E-9D48EAD01A1E@deitel.com> Message-ID: Paul, Sorry for the very late response! I would suggest passing in a function as a custom argument which takes the frame number and returns your parameter. For example (modified from the docs) import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation decades = 5 fig, ax = plt.subplots() xdata, ydata = [], [] ln, = plt.plot([], [], 'ro', animated=True) ax.set_xlim(1, 10**decades) ax.set_ylim(1, (10.0**(decades*(decades - 1)))) ax.set_yscale('log') ax.set_xscale('log') def init(): return ln, def update(frame, exp_func): xdata.append(frame) ydata.append(frame ** exp_func(frame)) ln.set_data(xdata, ydata) return ln, ani = FuncAnimation(fig, update, frames=np.logspace(0, decades), init_func=init, blit=True, fargs=(lambda frame: int(np.log10(frame)),)) plt.show() Tom On Tue, Jan 9, 2018 at 11:50 AM Paul Deitel wrote: > Hi Tom, > > Thanks for your response. > > Same figure/artists. > > Basically, for the function called by FuncAnimation, I?d like one of my > custom arguments to change after some number of frames. I did not find a > good way to do that, so I was thinking I could have one animation that does > the first set of frames with the initial custom argument value, followed by > another animation that does the remaining frames with a different custom > argument value. > > Thanks, > Paul > > On Jan 9, 2018, at 8:15 AM, Thomas Caswell wrote: > > When you say "another animation" do you mean different data on the same > artists in the same figure, different artists in the same figure or a > different figure altogether? > > In the first cases I think you could use a generator to sticky tape your > data together. In the second two you will have to roll your own. > > Do you need to be able to change the chain while it is running? If so, > what are you using to get your concurrencey? > > Tom > > On Mon, Jan 8, 2018, 12:38 Paul Deitel wrote: > >> I am trying to chain together a series of animations. Is there a callback >> mechanism of some sort that could be used to launch a new animation when >> another animation completes? >> >> >> >> _______________________________________________ >> 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 tcaswell at gmail.com Fri Apr 20 14:18:06 2018 From: tcaswell at gmail.com (Thomas Caswell) Date: Fri, 20 Apr 2018 18:18:06 +0000 Subject: [Matplotlib-users] automatic list of r'$2$'... In-Reply-To: <91b0196a-ad66-4f62-4cb6-d8106c0b659e@gmail.com> References: <769F7595-A888-467A-A120-9543BB59DC3B@netcourrier.com> <1513194125.1501.5.camel@lma.cnrs-mrs.fr> <1EDAF8CF-4C04-4E78-B0E1-012A042FD096@netcourrier.com> <91b0196a-ad66-4f62-4cb6-d8106c0b659e@gmail.com> Message-ID: The 'r' prefix tells python to not try an interpret any escape sequences (such at \t for 'tab' and '\n' for a new line) as escape sequences. This is part of the core python language, not Matplotlib or latex specific! If you did not use raw string and wanted to use ? (theta) as '$\theta$` python would go 'Ah ha! they asked for the string "$" " "h" "e" "t" "a" "$" ' which is not what you wanted. To get around this you can either do "$\\theta$" or r"$\theta$. Using raw strings is probably the better option as future versions of python will fail on unknown escape sequences so _every_ \ in your latex would have to be \\. Tom On Sat, Dec 23, 2017 at 4:39 PM Christophe BAL (via GMAIL) < projetmbc at gmail.com> wrote: > Hello. > > > One question: why do you use raw strings ? > > > One suggestion: with Python 3.6, you can use *fr"${x}$"* or simply > *f"${x}$"* if you don't really need raw strings. > > Le 23/12/2017 ? 22:01, Vincent Douce Mathoscope a ?crit : > > thanks Fabrice > the problems seems to be : > i get for Lrx : > '$0', '$1', '$2' > instead of > r'$0', r'$1', r'$2' > the "r" disappears > as the r is not in the chain is seems not to be considered by python as an element to keep ? > Vincent > > > Le 13 d?c. 2017 ? 20:42, Fabrice Silva a ?crit : > > Le mercredi 13 d?cembre 2017, Vincent Douce Mathoscope a ?crit : > > hi > i try this : > ''' > Lx,x,Ly,y=[],xmin,[],ymin > Lrx,Lry=[],[] > while (x<=xmax): > Lx.append(x) > Lrx.append("$".join(["r'",str(x),"'"])) > x+=1 > while (y<=ymax): > Ly.append(y) > y+=1 > ''' > but it creates a Lrx list like this : > ["r'$-2.5$'", "r'$-1.5$'", "r'$-0.5$'", "r'$0.5$'", "r'$1.5$'", > "r'$2.5$'"] > and i want to obtain > [r'$-2.5$', r'$-1.5$', r'$-0.5$', r'$0.5$', r'$1.5$', r'$2.5$'] > > > My suggestion > > import numpy as np > tmpx = [(x, r'$%s' % x) for x in np.arange(xmin, xmax, 1)] > Lx, Lrx = zip(*tmpx) > > Idem for the y stuff. > If you prefer to keep the while loop, change the Lrx line to > Lrx.append(r"$%s$" %x) > or > Lrx.append(r"${}$".format(x)) > Note that you can add format specification in both solutions. > > > _______________________________________________ > Matplotlib-users mailing listMatplotlib-users at python.orghttps://mail.python.org/mailman/listinfo/matplotlib-users > > > ?????????????????????????? > Vincent Douce > :=: Mathoscope :=: > http://mathoscope.xyz > 06?13?11?07?26 > Bagn?res de Bigorre 65200 > > > > > > _______________________________________________ > Matplotlib-users mailing listMatplotlib-users at python.orghttps://mail.python.org/mailman/listinfo/matplotlib-users > > > -- > Christophe BAL > Enseignant Agr?g? de Math?matiques > Programmeur Python Amateur > > _______________________________________________ > 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 michalwd1979 at o2.pl Sun Apr 22 16:43:23 2018 From: michalwd1979 at o2.pl (michalwd1979) Date: Sun, 22 Apr 2018 22:43:23 +0200 Subject: [Matplotlib-users] =?utf-8?q?matplotlib_in_GTK3_-_interactive_wi?= =?utf-8?q?ndow_while_not_calling_Gtk=2Emain=28=29?= Message-ID: <4e4ed31da3c44983b0bc6771854415f7@grupawp.pl> Dear Members, Recently I upgraded to from matplotlib 1.4.3 + gtk2 to matplotlib 2.2.2 + gtk3 and I have a problems with porting my old code. I'm using matplotlib in Gtk window with typical: win = Gtk.window() vbox = Gtk.Box(...) win.add(vbox) fig = pylab.figure() canvas = FigureCanvas(fig) toolbar = NavigationToolbar(canvas, fig) axis = fig.add_axes(...) vbox.pack_start(canvas,...) vbox.pack_start(toolbar,....) win.show_all() while(Gtk.events_pending()): Gtk.main_iteration() After this code I have a valid window on screen however it does not reacts on mouse clicks (zooming etc.) until calling Gtk.main_iteration() in loop or Gtk.main(). I can understand why, however it was working differently with old matplotlib and gtk2 (window was responsive all time). The rest of my code is a python "Text User Interface" application (controlled by commands typed to terminal), the window is only for showing the results (animated waveform). Now I would like to keep the application as it is, but also to have responsive matplotlib window, without calling Gtk.main(). Is it possible? If yes, then how to do this? Sorry for the long mail - I have no idea how to describe the problem shortly and all examples I found always have Gtk.main() called so they are in fact full GTK programs. I want a simple text program with matplotlib window as a "result showing" addition only. Best Regards, Michael Widlok -------------- next part -------------- An HTML attachment was scrubbed... URL: From pierre.haessig at crans.org Wed Apr 25 08:34:47 2018 From: pierre.haessig at crans.org (Pierre Haessig) Date: Wed, 25 Apr 2018 14:34:47 +0200 Subject: [Matplotlib-users] double tick labels (bottom and top, but with different labels) Message-ID: <1c4d0a47-aa0c-8430-ecc3-c9108409a6fe@crans.org> Hello, I'd like to know if it's possible to get a sort of double tick labeling (e.g. bottom and top), but with different labels. One way to think of my use case is that there are two different units for the x data (or more precisely in my case, I've two different x quantities which are bound by a linear relationship). The result I'd like is the right part of the attached image (it's a Gimp-edited mockup composition of the two actual plots on the left). I've tried to play with the double labeling of a single axe. Indeed, the following two calls put the double labeling ax1.xaxis.set_ticks_position('both') ax1.xaxis.set_tick_params(labeltop=True) However, when I want to alter only the top labels using for tick, l in zip(ax1.xaxis.get_major_ticks(), l2): ??? tick.set_label2(l) I get no visible change on the plot. (full script attached). Did I need to call some update ? Did I miss something with the proper way to call Tick.set_label2? Looking at the source code of ax1.xaxis.set_ticklabels, there is something I don't get. First it sets a FixedFormatter(ticklabels), and then it sets label1 and/or label2 for each Tick object. So in the end, where is the text coming from? Also, to complement the second series of tick labels, I'd like a second axis label as well. However, I only know ax.xaxis.set_label_position('top') to move xlabel to the top, not to get a 2nd one... As an alternative approach, I see twinx. I didn't try it yet, because I feel like my objective is not of the objective of twinx (e.g. I'm plotting only a single dataset, not two). However, I suspect it's possible to 'bend" twinx to get what I want. What do you think. Thank you in advance for your ideas. Best, Pierre -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: double_labels_mockup.png Type: image/png Size: 69026 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: DoubleTicksTest.py Type: text/x-python Size: 1211 bytes Desc: not available URL: From mdboom at gmail.com Wed Apr 25 08:59:51 2018 From: mdboom at gmail.com (Michael Droettboom) Date: Wed, 25 Apr 2018 12:59:51 +0000 Subject: [Matplotlib-users] 2018 John Hunter Excellence in Plotting Contest Message-ID: In memory of John Hunter, we are pleased to be reviving the SciPy John Hunter Excellence in Plotting Competition for 2018. This open competition aims to highlight the importance of data visualization to scientific progress and showcase the capabilities of open source software. Participants are invited to submit scientific plots to be judged by a panel. The winning entries will be announced and displayed at the conference. John Hunter?s family and NumFocus are graciously sponsoring cash prizes for the winners in the following amounts: - 1st prize: $1000 - 2nd prize: $750 - 3rd prize: $500 - Entries must be submitted by June, 8th to the form at https://goo.gl/forms/7q86zgu5OYUOjODH3. - Winners will be announced at Scipy 2018 in Austin, TX. - Participants do not need to attend the Scipy conference. - Entries may take the definition of ?visualization? rather broadly. Entries may be, for example, a traditional printed plot, an interactive visualization for the web, or an animation. - Source code for the plot must be provided, in the form of Python code and/or a Jupyter notebook, along with a rendering of the plot in a widely used format. This may be, for example, PDF for print, standalone HTML and Javascript for an interactive plot, or MPEG-4 for a video. If the original data can not be shared for reasons of size or licensing, "fake" data may be substituted, along with an image of the plot using real data. - Each entry must include a 300-500 word abstract describing the plot and its importance for a general scientific audience. - Entries will be judged on their clarity, innovation and aesthetics, but most importantly for their effectiveness in communicating a real-world problem. Entrants are encouraged to submit plots that were used during the course of research or work, rather than merely being hypothetical. - SciPy reserves the right to display any and all entries, whether prize-winning or not, at the conference, use in any materials or on its website, with attribution to the original author(s). SciPy John Hunter Excellence in Plotting Competition Co-Chairs Thomas Caswell Michael Droettboom Nelle Varoquaux -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent.adrien at gmail.com Wed Apr 25 11:52:25 2018 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Wed, 25 Apr 2018 08:52:25 -0700 Subject: [Matplotlib-users] double tick labels (bottom and top, but with different labels) In-Reply-To: <1c4d0a47-aa0c-8430-ecc3-c9108409a6fe@crans.org> References: <1c4d0a47-aa0c-8430-ecc3-c9108409a6fe@crans.org> Message-ID: <494b1361-d059-c536-6856-df4de8f247e1@gmail.com> Hi Pierre, I am not sure that label2 can be used for what you want to do. See for example: https://github.com/matplotlib/matplotlib/issues/8181 . If it can, I would be eager to know too :)! But I have currently little hopes that there is an easy *dedicated* method available right now, as Jody K. recently opened an issue on the GitHub tracker, about a very similar problem: https://github.com/matplotlib/matplotlib/issues/10976 At least, as a workaround, a twinned axis allows to get things reasonably working without too much hassle (I think). Here is an example that uses uses `FuncFormatter` and seems to be OK, even when interactively playing with it. ```python import matplotlib.pyplot as plt from matplotlib.ticker import FuncFormatter, MultipleLocator fig, ax = plt.subplots(num="example_pierre", clear=True) # A dummy plot xx, yy = [10, 20, 30], [1, 4, 9] ax.plot(xx, yy) ax.set_ylabel("An y-label") ax.set_xlabel("Quantity $x$") ax.xaxis.set_major_locator(MultipleLocator(10)) # Secondary labelling with twiny k = 5 ax1 = ax.twiny() ax1.plot(xx, yy, ls="", color="none") # dummy trace ax1.xaxis.set_major_locator(ax.xaxis.get_major_locator()) ax1.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: f"{k*x:g}")) ax1.set_xlabel(f"{k} times quantity $x$") fig.show() fig.savefig(fig.get_label() + ".pdf") ``` Hopefully this helps a bit. Best Adrien PS: If there are better solution to share the ticker and the view limits, I am interesting to know about it :). Le 25/04/2018 ? 05:34, Pierre Haessig a ?crit?: > Hello, > > > I'd like to know if it's possible to get a sort of double tick labeling > (e.g. bottom and top), but with different labels. One way to think of my > use case is that there are two different units for the x data (or more > precisely in my case, I've two different x quantities which are bound by > a linear relationship). > > The result I'd like is the right part of the attached image (it's a > Gimp-edited mockup composition of the two actual plots on the left). > > I've tried to play with the double labeling of a single axe. Indeed, the > following two calls put the double labeling > > ax1.xaxis.set_ticks_position('both') > ax1.xaxis.set_tick_params(labeltop=True) > > However, when I want to alter only the top labels using > > for tick, l in zip(ax1.xaxis.get_major_ticks(), l2): > ??? tick.set_label2(l) > > I get no visible change on the plot. (full script attached). Did I need > to call some update ? > > Did I miss something with the proper way to call Tick.set_label2? > > Looking at the source code of ax1.xaxis.set_ticklabels, there is > something I don't get. First it sets a FixedFormatter(ticklabels), and > then it sets label1 and/or label2 for each Tick object. So in the end, > where is the text coming from? > > > Also, to complement the second series of tick labels, I'd like a second > axis label as well. However, I only know > ax.xaxis.set_label_position('top') to move xlabel to the top, not to get > a 2nd one... > > > As an alternative approach, I see twinx. I didn't try it yet, because I > feel like my objective is not of the objective of twinx (e.g. I'm > plotting only a single dataset, not two). However, I suspect it's > possible to 'bend" twinx to get what I want. What do you think. > > > Thank you in advance for your ideas. > > > Best, > > Pierre > > > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- A non-text attachment was scrubbed... Name: example_pierre.pdf Type: application/pdf Size: 13461 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: example_pierre.py Type: text/x-python Size: 679 bytes Desc: not available URL: From jklymak at uvic.ca Wed Apr 25 12:20:24 2018 From: jklymak at uvic.ca (Jody Klymak) Date: Wed, 25 Apr 2018 09:20:24 -0700 Subject: [Matplotlib-users] double tick labels (bottom and top, but with different labels) In-Reply-To: <494b1361-d059-c536-6856-df4de8f247e1@gmail.com> References: <1c4d0a47-aa0c-8430-ecc3-c9108409a6fe@crans.org> <494b1361-d059-c536-6856-df4de8f247e1@gmail.com> Message-ID: <0296CDE6-CB4D-4A07-AAAA-7507331647B1@uvic.ca> Yes, this is the goal and will be implimented for 3.0 if the approach is accepted. See also https://github.com/matplotlib/matplotlib/issues/11005 Comments very welcome. But for now Adrien?s workaround is the best we have. Cheers, Jody > On 25 Apr 2018, at 08:52, vincent.adrien at gmail.com wrote: > > Hi Pierre, > > I am not sure that label2 can be used for what you want to do. See for > example: https://github.com/matplotlib/matplotlib/issues/8181 . If it > can, I would be eager to know too :)! But I have currently little hopes > that there is an easy *dedicated* method available right now, as Jody K. > recently opened an issue on the GitHub tracker, about a very similar > problem: https://github.com/matplotlib/matplotlib/issues/10976 > > At least, as a workaround, a twinned axis allows to get things > reasonably working without too much hassle (I think). Here is an example > that uses uses `FuncFormatter` and seems to be OK, even when > interactively playing with it. > ```python > import matplotlib.pyplot as plt > from matplotlib.ticker import FuncFormatter, MultipleLocator > > fig, ax = plt.subplots(num="example_pierre", clear=True) > > # A dummy plot > xx, yy = [10, 20, 30], [1, 4, 9] > ax.plot(xx, yy) > ax.set_ylabel("An y-label") > ax.set_xlabel("Quantity $x$") > ax.xaxis.set_major_locator(MultipleLocator(10)) > > # Secondary labelling with twiny > k = 5 > ax1 = ax.twiny() > ax1.plot(xx, yy, ls="", color="none") # dummy trace > ax1.xaxis.set_major_locator(ax.xaxis.get_major_locator()) > ax1.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: f"{k*x:g}")) > ax1.set_xlabel(f"{k} times quantity $x$") > > fig.show() > fig.savefig(fig.get_label() + ".pdf") > ``` > > Hopefully this helps a bit. > > Best > Adrien > > PS: If there are better solution to share the ticker and the view > limits, I am interesting to know about it :). > > > Le 25/04/2018 ? 05:34, Pierre Haessig a ?crit : >> Hello, >> >> >> I'd like to know if it's possible to get a sort of double tick labeling >> (e.g. bottom and top), but with different labels. One way to think of my >> use case is that there are two different units for the x data (or more >> precisely in my case, I've two different x quantities which are bound by >> a linear relationship). >> >> The result I'd like is the right part of the attached image (it's a >> Gimp-edited mockup composition of the two actual plots on the left). >> >> I've tried to play with the double labeling of a single axe. Indeed, the >> following two calls put the double labeling >> >> ax1.xaxis.set_ticks_position('both') >> ax1.xaxis.set_tick_params(labeltop=True) >> >> However, when I want to alter only the top labels using >> >> for tick, l in zip(ax1.xaxis.get_major_ticks(), l2): >> tick.set_label2(l) >> >> I get no visible change on the plot. (full script attached). Did I need >> to call some update ? >> >> Did I miss something with the proper way to call Tick.set_label2? >> >> Looking at the source code of ax1.xaxis.set_ticklabels, there is >> something I don't get. First it sets a FixedFormatter(ticklabels), and >> then it sets label1 and/or label2 for each Tick object. So in the end, >> where is the text coming from? >> >> >> Also, to complement the second series of tick labels, I'd like a second >> axis label as well. However, I only know >> ax.xaxis.set_label_position('top') to move xlabel to the top, not to get >> a 2nd one... >> >> >> As an alternative approach, I see twinx. I didn't try it yet, because I >> feel like my objective is not of the objective of twinx (e.g. I'm >> plotting only a single dataset, not two). However, I suspect it's >> possible to 'bend" twinx to get what I want. What do you think. >> >> >> Thank you in advance for your ideas. >> >> >> Best, >> >> Pierre >> >> >> >> >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users at python.org >> https://mail.python.org/mailman/listinfo/matplotlib-users >> > > _______________________________________________ > 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 pierre.haessig at crans.org Thu Apr 26 11:03:29 2018 From: pierre.haessig at crans.org (Pierre Haessig) Date: Thu, 26 Apr 2018 17:03:29 +0200 Subject: [Matplotlib-users] double tick labels (bottom and top, but with different labels) In-Reply-To: <0296CDE6-CB4D-4A07-AAAA-7507331647B1@uvic.ca> References: <1c4d0a47-aa0c-8430-ecc3-c9108409a6fe@crans.org> <494b1361-d059-c536-6856-df4de8f247e1@gmail.com> <0296CDE6-CB4D-4A07-AAAA-7507331647B1@uvic.ca> Message-ID: Thanks for all your feedback. Interesting to see that there are indeed issues and PR on this topic. Looking at issue https://github.com/matplotlib/matplotlib/issues/10976, it's makes no relation to the label2 https://github.com/matplotlib/matplotlib/issues/8181. Seems more like a "smart twinx", because the ENH propose that the ticks are not necessarily at the same position. In my case, since I can use the same xtick positions, I think in the end I can get away with just using one FuncFormatter which shows the two numbers. Using Adrien's suggestion, I need to try something like FuncFormatter(lambda x, pos: f"{x} -- {a*x+b}")). Best, Pierre From pierre.haessig at crans.org Thu Apr 26 11:09:36 2018 From: pierre.haessig at crans.org (Pierre Haessig) Date: Thu, 26 Apr 2018 17:09:36 +0200 Subject: [Matplotlib-users] 2018 John Hunter Excellence in Plotting Contest In-Reply-To: References: Message-ID: Hi, Is there a web page that collects the links to the results of the previous editions ? I found the 2013 edition website http://conference.scipy.org/jhepc2013/ I also found 2016 winner https://scipy2016.scipy.org/ehome/146062/332971/ with links to previous galleries, but 2014 and 2015 links are broken (http://stsdas.stsci.edu/download/mdroe/plotting/ and http://stsdas.stsci.edu/download/mdroe/plotting-2015/) Best, Pierre Le 25/04/2018 ? 14:59, Michael Droettboom a ?crit?: > > In memory of John Hunter, we are pleased to be reviving the SciPy John > Hunter Excellence in Plotting Competition for 2018. This open > competition aims to highlight the importance of data visualization to > scientific progress and showcase the capabilities of open source software. > > > Participants are invited to submit scientific plots to be judged by a > panel. The winning entries will be announced and displayed at the > conference. > > > John Hunter?s family and NumFocus are graciously sponsoring cash > prizes for the winners in the following amounts: > > > * > > 1st prize: $1000 > > * > > 2nd prize: $750 > > * > > 3rd prize: $500 > > > * > > Entries must be submitted by June, 8thto the form at > https://goo.gl/forms/7q86zgu5OYUOjODH3. > > * > > Winners will be announced at Scipy 2018 in Austin, TX. > > * > > Participants do not need to attend the Scipy conference. > > * > > Entries may take the definition of ?visualization? rather broadly. > Entries may be, for example, a traditional printed plot, an > interactive visualization for the web, or an animation. > > * > > Source code for the plot must be provided, in the form of Python > code and/or a Jupyter notebook, along with a rendering of the plot > in a widely used format.? This may be, for example, PDF for print, > standalone HTML and Javascript for an interactive plot, or MPEG-4 > for a video. If the original data can not be shared for reasons of > size or licensing, "fake" data may be substituted, along with an > image of the plot using real data. > > * > > Each entry must include a 300-500 word abstract describing the > plot and its importance for a general scientific audience. > > * > > Entries will be judged on their clarity, innovation and > aesthetics, but most importantly for their effectiveness in > communicating a real-world problem. Entrants are encouraged to > submit plots that were used during the course of research or work, > rather than merely being hypothetical. > > * > > SciPy reserves the right to display any and all entries, whether > prize-winning or not, at the conference, use in any materials or > on its website, with attribution to the original author(s). > > > SciPy John Hunter Excellence in Plotting Competition Co-Chairs > > Thomas Caswell > > Michael Droettboom > > Nelle Varoquaux > > > > _______________________________________________ > 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 vincent.adrien at gmail.com Thu Apr 26 13:46:21 2018 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Thu, 26 Apr 2018 10:46:21 -0700 Subject: [Matplotlib-users] double tick labels (bottom and top, but with different labels) In-Reply-To: References: <1c4d0a47-aa0c-8430-ecc3-c9108409a6fe@crans.org> <494b1361-d059-c536-6856-df4de8f247e1@gmail.com> <0296CDE6-CB4D-4A07-AAAA-7507331647B1@uvic.ca> Message-ID: <994c9049-a7d4-23d3-9bcc-8922793673e6@gmail.com> Hi Pierre, Related to your last idea, maybe you'll find useful the following formatter: ```python FuncFormatter(lambda x, pos: f"{x:g}\n{a*x + b:g}") ``` as one can multiline strings as tick labels, to get something as shown in the attached PDF (the whole script is provided as well). I guess that one can even do fancier stuff by leveraging the [string formatting Python language](https://docs.python.org/3/library/string.html#format-specification-mini-language). If you find a better way to achieve what you want, please note that there would be at least one person glad to read about ;). Best, Adrien On 04/26/2018 08:03 AM, Pierre Haessig wrote: > Thanks for all your feedback. Interesting to see that there are indeed > issues and PR on this topic. > > Looking at issue https://github.com/matplotlib/matplotlib/issues/10976, > it's makes no relation to the label2 > https://github.com/matplotlib/matplotlib/issues/8181. Seems more like a > "smart twinx", because the ENH propose that the ticks are not > necessarily at the same position. > > In my case, since I can use the same xtick positions, I think in the end > I can get away with just using one FuncFormatter which shows the two > numbers. Using Adrien's suggestion, I need to try something like > FuncFormatter(lambda x, pos: f"{x} -- {a*x+b}")). > > Best, > > Pierre > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- A non-text attachment was scrubbed... Name: example_bis_pierre.py Type: text/x-python Size: 548 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: example_bis_pierre.pdf Type: application/pdf Size: 151419 bytes Desc: not available URL: From tcaswell at gmail.com Fri Apr 27 20:45:53 2018 From: tcaswell at gmail.com (Thomas Caswell) Date: Sat, 28 Apr 2018 00:45:53 +0000 Subject: [Matplotlib-users] matplotlib in GTK3 - interactive window while not calling Gtk.main() In-Reply-To: <4e4ed31da3c44983b0bc6771854415f7@grupawp.pl> References: <4e4ed31da3c44983b0bc6771854415f7@grupawp.pl> Message-ID: Michael, If you are doing custom embedding I suggest staying away from `pyplot` altogether, it maintains global state you may not want, see for example https://matplotlib.org/gallery/user_interfaces/embedding_in_gtk3_sgskip.html#sphx-glr-gallery-user-interfaces-embedding-in-gtk3-sgskip-py . For the long answer to your question, see https://github.com/matplotlib/matplotlib/pull/4779 (which I really need to finish and get merged). In short, to have both an interactive prompt and a window you need to have an 'input hook' installed to time-share between the GUI event loop an the prompt event loop. It sounds like you change a bunch of things at once (gtk2 -> gtk3 + matplotlib version bumps), did you also change IPython versions? If so, you will need to use their input hook mechanism explicitly (`%matplotlib gtk3` should do the trick) as they moved from readline -> ptprompt so the input hooks the GUI libraries ship no longer work. It may also be worth checking the value of `mpl.get_backend()` to make sure pyplot as not defaulted to another GUI framework (ex Qt5) and you have 2 GUI frameworks in the same process conflicting with each other! Hope that helps! Tom On Sun, Apr 22, 2018 at 4:50 PM michalwd1979 wrote: > Dear Members, > Recently I upgraded to from matplotlib 1.4.3 + gtk2 to matplotlib 2.2.2 + > gtk3 and I have a problems with porting my old code. > I'm using matplotlib in Gtk window with typical: > win = Gtk.window() > vbox = Gtk.Box(...) > win.add(vbox) > fig = pylab.figure() > canvas = FigureCanvas(fig) > toolbar = NavigationToolbar(canvas, fig) > axis = fig.add_axes(...) > vbox.pack_start(canvas,...) > vbox.pack_start(toolbar,....) > win.show_all() > while(Gtk.events_pending()): Gtk.main_iteration() > > After this code I have a valid window on screen however it does not reacts > on mouse clicks (zooming etc.) until calling Gtk.main_iteration() in loop > or Gtk.main(). I can understand why, however it was working differently > with old matplotlib and gtk2 (window was responsive all time). > The rest of my code is a python "Text User Interface" application > (controlled by commands typed to terminal), the window is only for showing > the results (animated waveform). Now I would like to keep the application > as it is, but also to have responsive matplotlib window, without calling > Gtk.main(). Is it possible? If yes, then how to do this? > > Sorry for the long mail - I have no idea how to describe the problem > shortly and all examples I found always have Gtk.main() called so they are > in fact full GTK programs. I want a simple text program with matplotlib > window as a "result showing" addition only. > Best Regards, > Michael Widlok > > > > > _______________________________________________ > 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 tcaswell at gmail.com Fri Apr 27 20:47:33 2018 From: tcaswell at gmail.com (Thomas Caswell) Date: Sat, 28 Apr 2018 00:47:33 +0000 Subject: [Matplotlib-users] ToolManager In-Reply-To: References: <349583cb-2bd6-454d-a1d6-9c45e6aeb6d7@Spark> Message-ID: Juan, Support for the toolmanager shipped in Matplotlib 2.2! Hopefully this will work now. Tom On Wed, Nov 15, 2017 at 7:20 PM Juan Nunez-Iglesias wrote: > If anyone can find time to respond to this, I promise a PR to the docs > explaining the solution?! > > On 13 Nov 2017, 6:09 PM +1100, Juan Nunez-Iglesias , > wrote: > > Hi, > > I?m trying to add elements to the matplotlib toolbar *using the Qt5 > backend*. I tried running this example code: > > https://matplotlib.org/examples/user_interfaces/toolmanager.html > > But unfortunately it fails when using Qt5 with the error > > fig.canvas.manager.toolmanager.add_tool('List', ListTools) > AttributeError: 'FigureManagerQT' object has no attribute ?toolmanager' > > Is toolmanager only available for GTK? Is there an equivalent way of > achieving what the script is doing in other backends? > > Thanks, > > Juan. > > _______________________________________________ > 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 jni.soma at gmail.com Fri Apr 27 21:21:21 2018 From: jni.soma at gmail.com (Juan Nunez-Iglesias) Date: Sat, 28 Apr 2018 11:21:21 +1000 Subject: [Matplotlib-users] ToolManager In-Reply-To: References: <349583cb-2bd6-454d-a1d6-9c45e6aeb6d7@Spark> Message-ID: <7d6cf3b9-aecd-4b22-90cf-b25494a7d28d@Spark> ??? Thank you! Will try it out shortly. On 28 Apr 2018, 10:47 AM +1000, Thomas Caswell , wrote: > Juan, > > Support for the toolmanager shipped in Matplotlib 2.2!? Hopefully this will work now. > > Tom > > > On Wed, Nov 15, 2017 at 7:20 PM Juan Nunez-Iglesias wrote: > > > If anyone can find time to respond to this, I promise a PR to the docs explaining the solution?! > > > > > > On 13 Nov 2017, 6:09 PM +1100, Juan Nunez-Iglesias , wrote: > > > > Hi, > > > > > > > > I?m trying to add elements to the matplotlib toolbar *using the Qt5 backend*. I tried running this example code: > > > > > > > > https://matplotlib.org/examples/user_interfaces/toolmanager.html > > > > > > > > But unfortunately it fails when using Qt5 with the error > > > > > > > > ? ? fig.canvas.manager.toolmanager.add_tool('List', ListTools) > > > > AttributeError: 'FigureManagerQT' object has no attribute ?toolmanager' > > > > > > > > Is toolmanager only available for GTK? Is there an equivalent way of achieving what the script is doing in other backends? > > > > > > > > Thanks, > > > > > > > > Juan. > > > > > > > _______________________________________________ > > > 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 michalwd1979 at o2.pl Mon Apr 30 12:08:45 2018 From: michalwd1979 at o2.pl (michalwd1979) Date: Mon, 30 Apr 2018 18:08:45 +0200 Subject: [Matplotlib-users] =?utf-8?q?Odp=3A_Re=3A__matplotlib_in_GTK3_-_?= =?utf-8?q?interactive_window_while_not_calling_Gtk=2Emain=28=29?= In-Reply-To: <> References: Message-ID: <98d501a5d59045a1b831be5e8542d89f@grupawp.pl> Thank You Tom, It seems that there is in fact quite a lot of changes needed to get this working. First of all I will try to fix that "pylab" issue and then look at the input hooks, but I am not sure if this is still valid for normal python (not IPython - see below). The backend is GTK3Agg - confirmed. I'm not using IPython, just normal python 2.7.14, and this was not changed, so it was only matplotlib and pygtk version change. The old code was creating a "waveform" window when requested (with the code presented before) and for input I was using readline module, the application has set of predefined commands that it executes. Now I am a bit surprised that it was working right from the begging.... (If someone want to see the code then I can post it here) By the way I thought? that having a responsive plot window (in fact only zooming/moving is important) in a command line based application is a common task, but it seems that it is not. Is there any example available for gtk+readline (or any other text input module) usage? Thanks again, Michael Widlok Dnia 28 kwietnia 2018 02:46 Thomas Caswell <tcaswell at gmail.com> napisa?(a): Michael, If you are doing custom embedding I suggest staying away from `pyplot` altogether, it maintains global state you may not want, see for example? matplotlib.org matplotlib.org ?.? For the long answer to your question, see? github.com github.com ?(which I really need to finish and get merged).? In short, to have both an interactive prompt and a window you need to have an 'input hook' installed to time-share between the GUI event loop an the prompt event loop.? It sounds like you change a bunch of things at once (gtk2 -> gtk3?+ matplotlib version bumps),? did you also change IPython versions?? If so, you will need to use their input hook mechanism explicitly (`%matplotlib gtk3` should do the trick) as they moved from readline -> ptprompt so the input hooks the GUI libraries ship no longer work.? It may also be worth checking the value of `mpl.get_backend()` to make sure pyplot as not defaulted to another GUI framework (ex Qt5) and you have 2 GUI frameworks in the same process conflicting with each other! Hope that helps! Tom On Sun, Apr 22, 2018 at 4:50 PM michalwd1979 < michalwd1979 at o2.pl > wrote: Dear Members, Recently I upgraded to from matplotlib 1.4.3 + gtk2 to matplotlib 2.2.2 + gtk3 and I have a problems with porting my old code. I'm using matplotlib in Gtk window with typical: win = Gtk.window() vbox = Gtk.Box(...) win.add(vbox) fig = pylab.figure() canvas = FigureCanvas(fig) toolbar = NavigationToolbar(canvas, fig) axis = fig.add_axes(...) vbox.pack_start(canvas,...) vbox.pack_start(toolbar,....) win.show_all() while(Gtk.events_pending()): Gtk.main_iteration() After this code I have a valid window on screen however it does not reacts on mouse clicks (zooming etc.) until calling Gtk.main_iteration() in loop or Gtk.main(). I can understand why, however it was working differently with old matplotlib and gtk2 (window was responsive all time). The rest of my code is a python "Text User Interface" application (controlled by commands typed to terminal), the window is only for showing the results (animated waveform). Now I would like to keep the application as it is, but also to have responsive matplotlib window, without calling Gtk.main(). Is it possible? If yes, then how to do this? Sorry for the long mail - I have no idea how to describe the problem shortly and all examples I found always have Gtk.main() called so they are in fact full GTK programs. I want a simple text program with matplotlib window as a "result showing" addition only. Best Regards, Michael Widlok -------------- next part -------------- An HTML attachment was scrubbed... URL: