From parker.charles at gmail.com Tue May 4 17:41:00 2021 From: parker.charles at gmail.com (Chad Parker) Date: Tue, 4 May 2021 17:41:00 -0400 Subject: [Matplotlib-users] Remove Axes, Rescale Others to Fill Figure Message-ID: All- I frequently find myself in a position where I am programmatically generating figures with many subplots. For example, I might have data from 8 channels for 10 experimental runs and want to compare the different runs for each channel, ending up with 8 different figures (a figure for each channel), each of which has 10 stacked subplots (a subplot for each run). I look at the data I've plotted, and discover that, whoops, channel 0 had an error and didn't produce any data during run number 3, and now I have an empty axis in the middle of my figure. I'd like to be able to delete that empty axes and have the other axes grow to fill the now empty space. The Figure class provides the delaxes method, which removes the axes from the figure, but doesn't change the size of any of the other axes. So I still end up with a hole in my figure. I was hoping that tight_layout might take care of it, but it assumes the axes are still there. Is there an easy way to do this? Failing that, what's the hard way (I assume it exists)? Thank you, --Chad # generate some data (only 2 channels/5 runs in this example) nc, nr, nd = 2, 5, 12 data = {c: {r: [random() for x in range(nd)] for r in range(nr)} for c in range(nc)} data[0][3] = [] # whoops, no data here. # save the handles here figaxlist = [] # for each channel for chan in data: nplots = len(data[chan].keys()) # create a figure with many subplots fig, axs = plt.subplots(nplots, sharex=True) figaxlist.append((fig, axs)) for run, ax in zip(data[chan].keys(), axs): # plot the data ax.plot(data[chan][run]) fig, axs = figaxlist[0] # removes axes, but leaves hole. fig.delaxes(fig.axes[3]) -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent.adrien at gmail.com Wed May 5 05:08:43 2021 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Wed, 5 May 2021 11:08:43 +0200 Subject: [Matplotlib-users] Remove Axes, Rescale Others to Fill Figure In-Reply-To: References: Message-ID: Hi Chad, I am no expert on the topic, but I found the `ax.update_geometry` method that may allow to solve your problem. See at the end of the following example adapted from your own code. ```python import matplotlib.pyplot as plt from numpy.random import random plt.ion() # generate some data (only 2 channels/5 runs in this example) nc, nr, nd = 2, 5, 12 data = {c: {r: [random() for x in range(nd)] for r in range(nr)} for c in range(nc)} data[0][3] = [] # whoops, no data here. # save the handles here figaxlist = [] # for each channel for chan in data: nplots = len(data[chan].keys()) # create a figure with many subplots fig, axs = plt.subplots(nplots, sharex=True) figaxlist.append((fig, axs)) for run, ax in zip(data[chan].keys(), axs): # plot the data ax.plot(data[chan][run], color=f"C{run}") fig, axs = figaxlist[0] # removes axes, but leaves hole. fig.delaxes(fig.axes[3]) # update the axes geometry information n_nonempty = len(fig.axes) # amount of non empty plots for idx, ax in enumerate(fig.axes): ax.change_geometry(n_nonempty, 1, idx+1) # assuming single column layout ``` Hopefully this is more or less what you are looking for. Regards, Adrien Le 04/05/2021 ? 23:41, Chad Parker a ?crit?: > All- > > I frequently find myself in a position where I am programmatically generating figures with many subplots. For example, I might have data from 8 channels for 10 experimental runs and want to compare the different runs for each channel, ending up with 8 different figures (a figure for each channel), each of which has 10 stacked subplots (a subplot for each run). > > I look at the data I've plotted, and discover that, whoops, channel 0 had an error and didn't produce any data during run number 3, and now I have an empty axis in the middle of my figure. I'd like to be able to delete that empty axes and have the other axes grow to fill the now empty space. > > The Figure class provides the delaxes method, which removes the axes from the figure, but doesn't change the size of any of the other axes. So I still end up with a hole in my figure. I was hoping that tight_layout might take care of it, but it assumes the axes are still there. > > Is there an easy way to do this? Failing that, what's the hard way (I assume it exists)? > > Thank you, > --Chad > > > # generate some data (only 2 channels/5 runs in this example) > nc, nr, nd = 2, 5, 12 > data = {c: {r: [random() for x in range(nd)] for r in range(nr)} for c in range(nc)} > data[0][3] = [] # whoops, no data here. > > # save the handles here > figaxlist = [] > # for each channel > for chan in data: > ? nplots = len(data[chan].keys()) > ? # create a figure with many subplots > ? fig, axs = plt.subplots(nplots, sharex=True) > ? figaxlist.append((fig, axs)) > ? for run, ax in zip(data[chan].keys(), axs): > ??? # plot the data > ??? ax.plot(data[chan][run]) > > fig, axs = figaxlist[0] > > # removes axes, but leaves hole. > fig.delaxes(fig.axes[3]) > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > From parker.charles at gmail.com Wed May 5 10:02:48 2021 From: parker.charles at gmail.com (Chad Parker) Date: Wed, 5 May 2021 10:02:48 -0400 Subject: [Matplotlib-users] Remove Axes, Rescale Others to Fill Figure In-Reply-To: References: Message-ID: Hi Adrien- This is exactly the effect I'm looking to achieve. Thank you. The only problem is that it appears to be a solution for only the near term: MatplotlibDeprecationWarning: The change_geometry function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use set_subplotspec instead. ax.change_geometry(n_nonempty, 1, idx+1) MatplotlibDeprecationWarning: The update_params function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. ax.change_geometry(n_nonempty, 1, idx+1) MatplotlibDeprecationWarning: The figbox attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use get_subplotspec().get_position(self.figure) instead. ax.change_geometry(n_nonempty, 1, idx+1) These messages suggest that there must be a way to accomplish this with subplotspecs. A little further digging and I came up with a very similar alternative: gs = gridspec.GridSpec(len(fig.axes), 1) for i, ax in enumerate(ig.axes): ax.set_subplotspec(gs[i]) Thanks for your solution! --Chad On Wed, May 5, 2021 at 3:09 AM vincent.adrien at gmail.com < vincent.adrien at gmail.com> wrote: > Hi Chad, > > I am no expert on the topic, but I found the `ax.update_geometry` method > that may allow to solve your problem. See at the end of the following > example adapted from your own code. > > ```python > import matplotlib.pyplot as plt > from numpy.random import random > plt.ion() > > # generate some data (only 2 channels/5 runs in this example) > nc, nr, nd = 2, 5, 12 > data = {c: {r: [random() for x in range(nd)] for r in range(nr)} for c in > range(nc)} > data[0][3] = [] # whoops, no data here. > > # save the handles here > figaxlist = [] > # for each channel > for chan in data: > nplots = len(data[chan].keys()) > # create a figure with many subplots > fig, axs = plt.subplots(nplots, sharex=True) > figaxlist.append((fig, axs)) > for run, ax in zip(data[chan].keys(), axs): > # plot the data > ax.plot(data[chan][run], color=f"C{run}") > > fig, axs = figaxlist[0] > > # removes axes, but leaves hole. > fig.delaxes(fig.axes[3]) > > # update the axes geometry information > n_nonempty = len(fig.axes) # amount of non empty plots > for idx, ax in enumerate(fig.axes): > ax.change_geometry(n_nonempty, 1, idx+1) # assuming single column > layout > ``` > > Hopefully this is more or less what you are looking for. > > Regards, > Adrien > > Le 04/05/2021 ? 23:41, Chad Parker a ?crit : > > All- > > > > I frequently find myself in a position where I am programmatically > generating figures with many subplots. For example, I might have data from > 8 channels for 10 experimental runs and want to compare the different runs > for each channel, ending up with 8 different figures (a figure for each > channel), each of which has 10 stacked subplots (a subplot for each run). > > > > I look at the data I've plotted, and discover that, whoops, channel 0 > had an error and didn't produce any data during run number 3, and now I > have an empty axis in the middle of my figure. I'd like to be able to > delete that empty axes and have the other axes grow to fill the now empty > space. > > > > The Figure class provides the delaxes method, which removes the axes > from the figure, but doesn't change the size of any of the other axes. So I > still end up with a hole in my figure. I was hoping that tight_layout might > take care of it, but it assumes the axes are still there. > > > > Is there an easy way to do this? Failing that, what's the hard way (I > assume it exists)? > > > > Thank you, > > --Chad > > > > > > # generate some data (only 2 channels/5 runs in this example) > > nc, nr, nd = 2, 5, 12 > > data = {c: {r: [random() for x in range(nd)] for r in range(nr)} for c > in range(nc)} > > data[0][3] = [] # whoops, no data here. > > > > # save the handles here > > figaxlist = [] > > # for each channel > > for chan in data: > > nplots = len(data[chan].keys()) > > # create a figure with many subplots > > fig, axs = plt.subplots(nplots, sharex=True) > > figaxlist.append((fig, axs)) > > for run, ax in zip(data[chan].keys(), axs): > > # plot the data > > ax.plot(data[chan][run]) > > > > fig, axs = figaxlist[0] > > > > # removes axes, but leaves hole. > > fig.delaxes(fig.axes[3]) > > > > _______________________________________________ > > 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 luca72.bertolotti at gmail.com Wed May 12 13:42:33 2021 From: luca72.bertolotti at gmail.com (Luca Bertolotti) Date: Wed, 12 May 2021 19:42:33 +0200 Subject: [Matplotlib-users] Plot problem with pyqtmatplotlib Message-ID: Hello i have done this and works: def prova(self): lista_r = [] lista_y = [] for a in range(40): val = self.tableWidget.item(a, 0) va = QTableWidgetItem(val) valdamettere = va.text() if valdamettere != '': lista_r.append(valdamettere) print(lista_r) lista_y = [] for a in range(40): val = self.tableWidget.item(a, 1) va = QTableWidgetItem(val) valdamettere = va.text() if valdamettere != '': lista_y.append(valdamettere) figure = Figure(figsize=(9.18, 6.25), dpi=55) axes = figure.gca() axes.set_title("Andamento Profilato") lista_r_mp = [] lista_y_mp = [] for a in range(len(lista_r)-1): print(float(lista_r[a]), float(lista_r[a+1])) test_r = np.linspace(float(lista_r[a]), float(lista_r[a+1])) lista_r_mp.append(test_r) for b in range(len(lista_y)-1): test_y = np.linspace(float(lista_y[b]), float(lista_y[b+1])) lista_y_mp.append(test_y) for c in range(len(lista_y_mp)): axes.plot(lista_r_mp[c], lista_y_mp[c]) axes.grid(True) axes.set_xlabel('Raggio') axes.set_ylabel('Y') canvas = FigureCanvas(figure) self.navi_toolbar = NavigationToolbar(canvas, self) self.vbl_one = QVBoxLayout(self.widget_3) self.vbl_one.addWidget(canvas) self.vbl_one.addWidget(self.navi_toolbar) All this works now i need to add to the same figure an old script def test(self): import numpy as np import warnings import matplotlib.pyplot as plt x = np.array([10, 20, 30, 40, ]) y = np.array([50, 60, 70, 80])#raggio print(x, y) p= np.poly1d(355) with warnings.catch_warnings(): warnings.simplefilter('ignore', np.RankWarning) p30 = np.poly1d(np.polyfit(x, y, 50)) valore_y_da_mettere = p30(355) print('p30 di 500/n') print(valore_y_da_mettere) self.lineEdit_2.setText(str(valore_y_da_mettere)) xp = np.linspace(0, 100, 100000) _ = plt.plot(x, y, '.', xp, p30(xp), '-') plt.ylim(50,80)#limiti asse y plt.xlim(10, 40)# limiti asse x plt.show() How i can add the test plot on the same figure of the function prova?? basically how i can change the plt in the figure.gca() -------------- next part -------------- An HTML attachment was scrubbed... URL: From quantum.analyst at gmail.com Sat May 8 05:12:08 2021 From: quantum.analyst at gmail.com (Elliott Sales de Andrade) Date: Sat, 08 May 2021 09:12:08 -0000 Subject: [Matplotlib-users] [ANN] Matplotlib 3.4.2 Message-ID: <3f9e266d-8c5e-e388-0b88-222ef0ef5d35@gmail.com> Hi all, We are pleased to announce the release of Matplotlib 3.4.2. This is the second bug fix release of the 3.4.x series. Pre-built wheels are available for most major platforms, and can be installed using `pip install matplotlib==3.4.2`. Other packages may also be available already; please check with your preferred source. We would like to thank the 13 authors over 46 pull requests for their contributions to this release. This release contains several critical bug fixes: * Generate wheels usable on older PyPy7.3.{0,1} * Fix compatibility with Python 3.10 * Add |subplot_mosaic| Axes in the order the user gave them to us * Correctly handle 'none' /facecolors/ in |do_3d_projection| * Ensure that Matplotlib is importable even if there's no HOME * Fix |CenteredNorm| with /halfrange/ * Fix |bar_label| for bars with NaN values * Fix clip paths when zoomed such that they are outside the figure * Fix creation of |RangeSlider| with /valinit/ * Fix handling of "d" glyph in backend_ps, fixing EPS output * Fix handling of datetime coordinates in |pcolormesh| with Pandas * Fix processing of some |errorbar| arguments * Fix removal of shared polar Axes * Fix resetting grid visibility * Fix subfigure indexing error and tight bbox * Fix textbox cursor color * Fix TkAgg event loop error on window close * Ignore errors for sip with no setapi (Qt4Agg import errors) For further details on new features, please see the What's new in Matplotlib 3.4.0 page: https://matplotlib.org/3.4.0/users/whats_new.html and for details of bugs fixed in 3.4.2, see the milestone on GitHub: https://github.com/matplotlib/matplotlib/milestone/63?closed=1 This release is signed by my GPG key. The fingerprint is: 23CA B59E 3332 F94D 26BE F037 8D86 E7FA E5EB 0C10 and it is also used to sign this message. -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 840 bytes Desc: OpenPGP digital signature URL: