From contact at bioasys.net Thu Jan 10 10:58:19 2019 From: contact at bioasys.net (bioquestions) Date: Thu, 10 Jan 2019 08:58:19 -0700 (MST) Subject: [Matplotlib-users] How do i use a button to switch between two different graphs in matplotlib Message-ID: <1547135899573-0.post@n5.nabble.com> I would like to be able to use a button press within an embedded tkinter matplotlib graph to switch from one graph to another. The code I have written does not replace the first graph with the second graph but just adds the second graph underneath the first graph. How can I get the button press to replace the first graph with the second graph rather than just add the second graph below the first graph? Here is my code: import matplotlib matplotlib.use("TkAgg") import matplotlib.pyplot as plt import numpy as np from tkinter import * from matplotlib.backends.backend_tkagg import ( FigureCanvasTkAgg, NavigationToolbar2Tk) # Implement the default Matplotlib key bindings. from matplotlib.backend_bases import key_press_handler def graph_one(): t = np.arange(0.0, 2.0, 0.01) s = 1 + np.sin(2 * np.pi * t) fig, ax = plt.subplots() ax.plot(t, s) ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='Graph One') #plt.show() return fig def graph_two(): t = np.arange(0.0, 2.0, 0.01) s = 1 + np.cos(2 * np.pi * t) fig, ax = plt.subplots() ax.plot(t, s) ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='Graph Two') #plt.show() return fig class matplotlibSwitchGraphs: def __init__(self, master): self.master = master self.frame = Frame(self.master) self.embed_graph_one() self.frame.pack(expand=YES, fill=BOTH) def embed_graph_one(self): fig = graph_one() canvas = FigureCanvasTkAgg(fig, self.master) canvas.draw() canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1) canvas.mpl_connect("key_press_event", self.on_key_press) toolbar = NavigationToolbar2Tk(canvas, self.master) toolbar.update() canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1) self.button = Button(self.master, text="Quit", command=self._quit) self.button.pack(side=BOTTOM) self.button_vol = Button(self.master, text="Switch Graphs", command=self.switch_graphs) self.button_vol.pack(side=BOTTOM) def embed_graph_two(self): fig = graph_two() canvas = FigureCanvasTkAgg(fig, self.master) canvas.draw() canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1) canvas.mpl_connect("key_press_event", self.on_key_press) toolbar = NavigationToolbar2Tk(canvas, self.master) toolbar.update() canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1) self.button = Button(self.master, text="Quit", command=self._quit) self.button.pack(side=BOTTOM) self.button_switch = Button(self.master, text="Switch Graphs", command=self.switch_graphs) self.button_switch.pack(side=BOTTOM) def on_key_press(event): print("you pressed {}".format(event.key)) key_press_handler(event, canvas, toolbar) def _quit(self): self.master.quit() # stops mainloop def switch_graphs(self): self.embed_graph_two() def main(): root = Tk() matplotlibSwitchGraphs(root) root.mainloop() if __name__ == '__main__': main() Any help would be greatly appreciated. -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From gmroldan at hudsonenergy.co.uk Thu Jan 10 12:03:47 2019 From: gmroldan at hudsonenergy.co.uk (gmroldan at hudsonenergy.co.uk) Date: Thu, 10 Jan 2019 12:03:47 -0500 Subject: [Matplotlib-users] Matplotlib-users Digest, Vol 42, Issue 1 Message-ID: <9800ceb7-4ac5-4ca4-b0ac-673be34e82f0@hudsonenergy.co.uk> ? The person you are trying to reach is no longer at Just Energy, please redirect your email accordingly. From jacopo.landi1 at gmail.com Mon Jan 14 09:12:32 2019 From: jacopo.landi1 at gmail.com (Jacopo Landi) Date: Mon, 14 Jan 2019 15:12:32 +0100 Subject: [Matplotlib-users] Installation issue In-Reply-To: References: <1543847561054-0.post@n5.nabble.com> Message-ID: Finally I uninstalled python and all downloaded packages and installed it again, following different instructions. Now pip runs very fine and a simple pip install matplotlib works! Thank you for the support! On Tue, 4 Dec 2018, 16:38 Antony Lee I would suggest removing the link to mpl-winbuild (which appears to not > have been updated for 4 years) and state something to the effect of > - either use the built wheels/conda packages (I think this is what the OP > needs) > - or use conda to get libpng set up > - or set it up on your own. > Once libpng and a recent enough MSVC are present, building Matplotlib > oneself is "reasonably" straightforward. > Antony > > On Tue, Dec 4, 2018 at 2:39 PM Thomas Caswell wrote: > >> If you are using conda it may also be worth looking at the recipe build >> script and / or the installation. >> >> Our official window install install instructions ( >> https://matplotlib.org/users/installing.html#build-windows ) point at >> matplotlib-winbuild so I think this is our problem to either fix or own >> complete install documentation in our docs. >> >> Tom >> >> >> >> >> On Mon, Dec 3, 2018 at 5:47 PM Paul Hobson wrote: >> >>> What I believe Ben means is that since the matplotlib development team >>> doesn't maintain those scripts, this list isn't the best place for your >>> question (as odd as that may seem). My recommendation would be to the look >>> through the open issues at the matplitlib-winbuild repository and check if >>> someone having a similar issue has figured out a solution. If not, you >>> could create a new issue at the repository explaining your predicament. >>> -Paul >>> >>> On Mon, Dec 3, 2018 at 2:18 PM Jacopo Landi >>> wrote: >>> >>>> I have already followed all that instructions...But still it gaves me >>>> this error and I can't understand what I'm doing wrong ?? >>>> >>>> On Mon, 3 Dec 2018, 18:38 Benjamin Root >>> >>>>> This seems to be an issue with >>>>> https://github.com/jbmohler/matplotlib-winbuild. You might want to >>>>> check there first. >>>>> >>>>> On Mon, Dec 3, 2018 at 9:32 AM Jack_Landis >>>>> wrote: >>>>> >>>>>> Dear all, >>>>>> >>>>>> I'm trying to install matplotlib on my pc (Windows 10). I got this >>>>>> error: >>>>>> >>>>>> $ python buildall.py >>>>>> Traceback (most recent call last): >>>>>> File "buildall.py", line 58, in >>>>>> main(options) >>>>>> File "buildall.py", line 11, in main >>>>>> utils.build_zlib() >>>>>> File >>>>>> >>>>>> "C:\Users\laj\AppData\Local\Programs\Python\Python37\Lib\site-packages\matplotlib-winbuild\utils.py", >>>>>> line 136, in build_zlib >>>>>> cmd.write(prepare_build_cmd(ZLIB_BUILD_CMD)) >>>>>> File >>>>>> >>>>>> "C:\Users\laj\AppData\Local\Programs\Python\Python37\Lib\site-packages\matplotlib-winbuild\utils.py", >>>>>> line 63, in prepare_build_cmd >>>>>> raise RuntimeError('Microsoft VS {} required'.format('2010' if >>>>>> VS2010 >>>>>> else '2008')) >>>>>> RuntimeError: Microsoft VS 2010 required >>>>>> >>>>>> I already have "Microsoft Visual C++ 2008 redistributable" installed >>>>>> (I have >>>>>> 2008, 2010, 2012, 2013, 2017 installed). What shall I do? >>>>>> >>>>>> Thank you very much! >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> 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 >>>>>> >>>>> _______________________________________________ >>>> 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 >>> >> >> >> -- >> Thomas Caswell >> tcaswell at gmail.com >> _______________________________________________ >> 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 gmroldan at hudsonenergy.co.uk Mon Jan 14 12:03:44 2019 From: gmroldan at hudsonenergy.co.uk (gmroldan at hudsonenergy.co.uk) Date: Mon, 14 Jan 2019 12:03:44 -0500 Subject: [Matplotlib-users] Matplotlib-users Digest, Vol 42, Issue 3 Message-ID: ? The person you are trying to reach is no longer at Just Energy, please redirect your email accordingly. From gmroldan at hudsonenergy.co.uk Tue Jan 15 12:07:27 2019 From: gmroldan at hudsonenergy.co.uk (gmroldan at hudsonenergy.co.uk) Date: Tue, 15 Jan 2019 12:07:27 -0500 Subject: [Matplotlib-users] Matplotlib-users Digest, Vol 42, Issue 4 Message-ID: ? The person you are trying to reach is no longer at Just Energy, please redirect your email accordingly. From mbatr27 at gmail.com Tue Jan 22 15:12:57 2019 From: mbatr27 at gmail.com (Matthew Bradley) Date: Tue, 22 Jan 2019 13:12:57 -0700 Subject: [Matplotlib-users] Boxplot quartiles Message-ID: Hi all, I have the following array: x = np.array([1920.5508, 513.4158, 1071.6049, 1412.2137, 1378.3534, 561.4679]) when I put it into a boxplot it shows a boxplot with values that I would get from np.percentile: np.percentile(x,[0,25,50,75,100],interpolation='linear') >>>array([ 513.4158 , 689.00215 , 1224.97915 , 1403.748625, 1920.5508 ]) I would like for the 1st and 3rd quartile to be calculated with a different interpolation and then display these different values in the boxplot, i.e. np.percentile(x,25,interpolation='lower') >>>561.4679 np.percentile(x,75,interpolation='higher') >>>1412.2137 Does anyone know if matplotlib can set which type of interpolation to use when it's calculating the percentiles? Thanks for your help! -- Matthew Bradley -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmhobson at gmail.com Tue Jan 22 19:19:50 2019 From: pmhobson at gmail.com (Paul Hobson) Date: Tue, 22 Jan 2019 16:19:50 -0800 Subject: [Matplotlib-users] Boxplot quartiles In-Reply-To: References: Message-ID: Matplotlib's boxplot function has two steps: 1) pass the data to cbook.boxplots_stats 2) pass the stats to Axes.bxp We did it this way so that people could skip step one and use their own stats with Axes.bxp. Axes.bxp expects a list of dictionaries with the following keys: 'label', 'mean', 'iqr', 'cilo', 'cihi', 'whishi', 'whislo', 'fliers', 'q1', 'med', 'q3' E.g, cilo & cihi are optional if you're not drawing the notch. We documented it here: https://matplotlib.org/gallery/statistics/bxp.html#sphx-glr-gallery-statistics-bxp-py I use this feature myself in a library I wrote for work: Compute custom boxplot stats: - https://github.com/Geosyntec/wqio/blob/master/wqio/features.py#L417 Pass that list of dictionaries to Axes.bxp: - https://github.com/Geosyntec/wqio/blob/master/wqio/features.py#L496 - https://github.com/Geosyntec/wqio/blob/master/wqio/viz.py#L261 On Tue, Jan 22, 2019 at 12:13 PM Matthew Bradley wrote: > Hi all, > > I have the following array: > > x = np.array([1920.5508, 513.4158, 1071.6049, 1412.2137, 1378.3534, > 561.4679]) > > when I put it into a boxplot it shows a boxplot with values that I would > get from np.percentile: > > np.percentile(x,[0,25,50,75,100],interpolation='linear') > >>>array([ 513.4158 , 689.00215 , 1224.97915 , 1403.748625, 1920.5508 ]) > > I would like for the 1st and 3rd quartile to be calculated with a > different interpolation and then display these different values in the > boxplot, i.e. > > np.percentile(x,25,interpolation='lower') > >>>561.4679 > > np.percentile(x,75,interpolation='higher') > >>>1412.2137 > > Does anyone know if matplotlib can set which type of interpolation to use > when it's calculating the percentiles? > > Thanks for your help! > > > -- > Matthew Bradley > _______________________________________________ > 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 mbatr27 at gmail.com Tue Jan 22 23:12:42 2019 From: mbatr27 at gmail.com (Matthew Bradley) Date: Tue, 22 Jan 2019 21:12:42 -0700 Subject: [Matplotlib-users] Boxplot quartiles In-Reply-To: References: Message-ID: This is great, thanks! On Tue, Jan 22, 2019 at 5:20 PM Paul Hobson wrote: > Matplotlib's boxplot function has two steps: > > 1) pass the data to cbook.boxplots_stats > 2) pass the stats to Axes.bxp > > We did it this way so that people could skip step one and use their own > stats with Axes.bxp. > > Axes.bxp expects a list of dictionaries with the following keys: > > 'label', 'mean', 'iqr', 'cilo', 'cihi', 'whishi', 'whislo', 'fliers', 'q1', 'med', 'q3' > > E.g, cilo & cihi are optional if you're not drawing the notch. > > We documented it here: > > https://matplotlib.org/gallery/statistics/bxp.html#sphx-glr-gallery-statistics-bxp-py > > I use this feature myself in a library I wrote for work: > Compute custom boxplot stats: > > - https://github.com/Geosyntec/wqio/blob/master/wqio/features.py#L417 > > Pass that list of dictionaries to Axes.bxp: > > - https://github.com/Geosyntec/wqio/blob/master/wqio/features.py#L496 > - https://github.com/Geosyntec/wqio/blob/master/wqio/viz.py#L261 > > > On Tue, Jan 22, 2019 at 12:13 PM Matthew Bradley > wrote: > >> Hi all, >> >> I have the following array: >> >> x = np.array([1920.5508, 513.4158, 1071.6049, 1412.2137, 1378.3534, >> 561.4679]) >> >> when I put it into a boxplot it shows a boxplot with values that I would >> get from np.percentile: >> >> np.percentile(x,[0,25,50,75,100],interpolation='linear') >> >>>array([ 513.4158 , 689.00215 , 1224.97915 , 1403.748625, 1920.5508 ]) >> >> I would like for the 1st and 3rd quartile to be calculated with a >> different interpolation and then display these different values in the >> boxplot, i.e. >> >> np.percentile(x,25,interpolation='lower') >> >>>561.4679 >> >> np.percentile(x,75,interpolation='higher') >> >>>1412.2137 >> >> Does anyone know if matplotlib can set which type of interpolation to use >> when it's calculating the percentiles? >> >> Thanks for your help! >> >> >> -- >> Matthew Bradley >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users at python.org >> https://mail.python.org/mailman/listinfo/matplotlib-users >> > -- Matthew Bradley -------------- next part -------------- An HTML attachment was scrubbed... URL: From irinkish at gmail.com Wed Jan 30 09:31:01 2019 From: irinkish at gmail.com (IK) Date: Wed, 30 Jan 2019 14:31:01 -0000 Subject: [Matplotlib-users] Labels alignmnet pie chart / matplotlib 2.1.0+ Message-ID: <1548858068236-0.post@n5.nabble.com> Hi, I am having a question regarding a pie-chart labels alignment. I'd like to have labels outside the pie-chart and centered to each wedge. According to the documentation page, "labeldistance" parameter enables to place labels outside the pie-chart, and "ha" & "va" parameters supposed to center. However, these two options (ha & va) seems not working on Matplotlib v2.1.0+. 1) With this example (pls see below), you can see that "car" label is not centered properly, it is a bit off the center. import matplotlib.pyplot as plt figure = plt.figure() axes = figure.add_subplot(111) axes.set_aspect(1) # circular pie y = [1,2,3, 4,8,16,18] label = ['car','domino', 'romancical','testing1', 'thisisthelonglabel', 'fffffffffffffffffffffffffffffffffffffffffff', 'as'] wedges, texts = plt.pie(y, radius=1.2, labels=label, labeldistance=1.0, rotatelabels =True, startangle = 10, wedgeprops = {"linewidth": 0.7, "edgecolor": "white"}, textprops = dict(ha="center", va="center")) # doesn't work plt.show() I added the following lines to force labels to be centered, which works but disabled a "labeldistance" parameter. So all my centered correctly, as I want labels are overlapping with the pie-chart circle now. wedges, texts = plt.pie(y, radius=1.2, labels=label, labeldistance=1.0, rotatelabels =True, startangle = 10, wedgeprops = {"linewidth": 0.7, "edgecolor": "white"}, textprops = dict(va="center")) for t in texts: #t.set_horizontalalignment("center") t.set_verticalalignment("center") plt.show() It seems that "va" option works perfectly for users of Matplotlib v 3.0.2, but it doesnt on v 2.2.2 Could you please advice if there is a solution for keeping "labeldistance" while using .set_horizontalalignment("center") ? P>S: Pls. note the same question is posted on stackoverflow.com: https://stackoverflow.com/questions/54441737/labels-alignmnet-pie-chart-matplotlib-2-1-0 Thanks -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html