From djpine at gmail.com Sun Jun 4 08:25:31 2017 From: djpine at gmail.com (David J Pine) Date: Sun, 4 Jun 2017 08:25:31 -0400 Subject: [Matplotlib-users] problems with Qt5 backend? Message-ID: The following script runs fine with pyqt version 4 but not version 5. With Qt5 the interactive plot window is too small, but the text remains at the size that would be correct for a larger properly sized window. I'm running Qt5 with the latest Anaconda installation on a Mac. Is this a problem with the matplotlib backend for Qt5? By the way, the version of the plot saved to the file text.pdf is correctly sized. from matplotlib.backends.backend_qt5agg \ import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure fig = Figure(figsize=(6, 4)) canvas = FigureCanvas(fig) ax = fig.add_subplot(111) ax.plot([1, 2, 3, 2, 3, 4, 3, 4, 5]) ax.set_title('A simple plot') ax.grid(True) ax.set_xlabel('time') ax.set_ylabel('volts') canvas.print_figure('test.pdf') canvas.show() -------------- next part -------------- An HTML attachment was scrubbed... URL: From djpine at gmail.com Wed Jun 14 15:43:12 2017 From: djpine at gmail.com (David J Pine) Date: Wed, 14 Jun 2017 15:43:12 -0400 Subject: [Matplotlib-users] Problem animating a histogram and movie at the same time Message-ID: I am having a problem animating a histogram and movie at the same time using matplotlib.animation.ArtistAnimation. The first program below, which makes an animated histogram using the "bar" routine works fine. If I substitute the two lines commented out for the two lines preceding those lines, it still works fine (using "plot" instead of 'bar"). For reasons that are not clear to me, I need make a list (ims) for animation for the histogram using the "bar" routine, and a list of lists for animation of the simple "plot" routine. There is a more serious problem with the second routine where I simultaneously animate a sequence of images using imshow and also try to make an animated histogram. It works fine if I plot the "histogram" using the "plot" routine but does not work if I use the "bar" routine. Can someone offer some help? I am running these on OSX 10.12.5, Python 3.5.2 or Python 3.6.1, and matplotlib 2.0.0 or 2.0.2 ---------------------------- import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation fig, ax = plt.subplots() ims = [] xh = np.random.randn(10) for i in range(100): xh = np.append(xh, np.random.randn(10)) a, b = np.histogram(xh, bins=24, normed=True) xx = 0.5*(b[:-1]+b[1:]) ax.set_xlim(-3, 3) ax.set_ylim(0, 0.5) im = ax.bar(xx, a, width=0.9*(b[1]-b[0]), color='C1') ims.append(im) # im, = ax.plot(xx, a, '-oC0') # ims.append([im]) ani = animation.ArtistAnimation(fig, artists=ims, interval=50, repeat=False) plt.show() ---------------------------- import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation def f(x, y): return np.sin(x) + np.cos(y) xm = np.linspace(0, 2 * np.pi, 120) ym = np.linspace(0, 2 * np.pi, 120).reshape(-1, 1) fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 3.5)) ax1.axis('off') ims = [] xh = np.random.randn(10) for i in range(100): xm += np.pi / 20. ym += np.pi / 20. im1 = ax1.imshow(f(xm, ym), cmap=plt.get_cmap('plasma'), aspect='equal', animated=True) xh = np.append(xh, np.random.randn(10)) a, b = np.histogram(xh, bins=24, normed=True) xx = 0.5*(b[:-1]+b[1:]) ax2.set_xlim(-3, 3) ax2.set_ylim(0, 0.5) # im2 = ax2.bar(xx, a, width=0.9*(b[1]-b[0]), color='C1') im2, = ax2.plot(xx, a, '-oC0') ims.append([im1, im2]) ani = animation.ArtistAnimation(fig, artists=ims, interval=50, repeat=False) # ani.save('junk.mp4') plt.show() ---------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From rmay31 at gmail.com Wed Jun 14 18:18:39 2017 From: rmay31 at gmail.com (Ryan May) Date: Wed, 14 Jun 2017 16:18:39 -0600 Subject: [Matplotlib-users] Problem animating a histogram and movie at the same time In-Reply-To: References: Message-ID: On Wed, Jun 14, 2017 at 1:43 PM, David J Pine wrote: > I am having a problem animating a histogram and movie at the same time > using matplotlib.animation.ArtistAnimation. > > The first program below, which makes an animated histogram using the "bar" > routine works fine. If I substitute the two lines commented out for the > two lines preceding those lines, it still works fine (using "plot" instead > of 'bar"). For reasons that are not clear to me, I need make a > list (ims) for animation for the histogram using the "bar" routine, and a > list of lists for animation of the simple "plot" routine. > > There is a more serious problem with the second routine where I > simultaneously animate a sequence of images using imshow and also try to > make an animated histogram. It works fine if I plot the "histogram" using > the "plot" routine but does not work if I use the "bar" routine. Can > someone offer some help? > > I am running these on OSX 10.12.5, Python 3.5.2 or Python 3.6.1, and > matplotlib 2.0.0 or 2.0.2 > David, Thanks for the complete examples, it made figuring this out really quick. ArtistAnimation expects to be given a list of lists (or tuples), where the inner collection contains all of the artists that should be rendered for a given frame. In the case of bar, it returns a BarCollection object (which I just learned), is a subclass of tuple. This explains why it works (by itself), when directly appended to the list given to ArtistAnimation; the BarCollection acts as the collection of artists that ArtistAnimation is expecting. In the case of the second example, ArtistAnimation is being given a list([BarCollection, Image]); because BarCollection isn't actually an Artist, it causes the problem. What you should try is: ims.append([im1] + list(im2)) This converts the BarCollection to a list of the individual Bar artists, and adds to the list containing the image; ArtistAnimation can understand this and it seems to work fine on my system. Ryan -- Ryan May -------------- next part -------------- An HTML attachment was scrubbed... URL: From jni.soma at gmail.com Fri Jun 23 00:17:25 2017 From: jni.soma at gmail.com (Juan Nunez-Iglesias) Date: Fri, 23 Jun 2017 14:17:25 +1000 Subject: [Matplotlib-users] Subplot x-axis shared with other subplots y-axis In-Reply-To: References: Message-ID: <85a1d34b-065e-4cc5-9f9c-f68c796c2802@Spark> Hey Tom, Thanks for that response, it was just what I needed! I had a fun infinite loop where the x-axis was updating the y-axis which was updating the x-axis which... =P But it was easy enough to sort out. =) I have a working orthogonal slice viewer here: https://github.com/jni/mpl-volume-viewer/ The problem I have now is that, if I set a mouse-click callback (this line and this line), and then I select any other tool from the toolbar, I get this super-obnoxious flickering, recorded here (macOS 10.12, Tk backend): https://www.dropbox.com/s/qvfmgp0x36p6rb9/mpl-click-bug.mov?dl=0 To reproduce: - Download slice_view.py and put it in your PYTHONPATH or current working directory - Download this example dataset: https://www.dropbox.com/s/dj3oarx7bqx4us2/E_z2_512_1um_CONTROL.tif?dl=1 - Run this code: import matplotlib matplotlib.use('TkAgg') from skimage import io import slice_view as sv filename = '/path/to/E_z2_512_1um_CONTROL.tif' image = io.imread(filename) / 4096 v = sv.SliceViewer(image, spacing=[5, 1, 1]) matplotlib.pyplot.show(block=True) Questions: 1) Any ideas about how to fix the flickering? 2) Is there a cross-backend way to add buttons to the toolbar? All the examples I've found online were backend-specific. (This way I could at least disable the callback at will.) Thanks! Juan. On 16 May 2017, 1:43 AM +1000, Thomas Caswell , wrote: > There are callbacks that fire when the limits are changed.? See > > https://matplotlib.org/examples/event_handling/viewlims.html > > for an example. > > This is probably the best route to go down as you can do other interesting things as the event goes by (like triggering computation, updating a openGL view window, etc) as well as updating the Matplotlib limits. > > Tom > > > On Mon, May 15, 2017 at 3:29 AM Juan Nunez-Iglesias wrote: > > > Hello, > > > > > > I?m trying to build an orthogonal-views volume viewer in Matplotlib like this one: > > > https://imagej.nih.gov/ij/docs/guide/images/OrthogonalViews.png > > > > > > For this to work, I need to share the y-axis of the YZ (right) view/subplot with the x-axis of the XZ (bottom) view/subplot. Is this possible? > > > > > > 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 ben.v.root at gmail.com Tue Jun 27 11:08:01 2017 From: ben.v.root at gmail.com (Benjamin Root) Date: Tue, 27 Jun 2017 11:08:01 -0400 Subject: [Matplotlib-users] Subplot x-axis shared with other subplots y-axis In-Reply-To: <85a1d34b-065e-4cc5-9f9c-f68c796c2802@Spark> References: <85a1d34b-065e-4cc5-9f9c-f68c796c2802@Spark> Message-ID: re: cross-backend way to add buttons: There is experimental feature called "ToolManager", but I think it is only implemented for a couple of backends currently. You can see an example here: http://matplotlib.org/examples/user_interfaces/toolmanager.html On Fri, Jun 23, 2017 at 12:17 AM, Juan Nunez-Iglesias wrote: > Hey Tom, > > Thanks for that response, it was just what I needed! I had a fun infinite > loop where the x-axis was updating the y-axis which was updating the x-axis > which... =P But it was easy enough to sort out. =) > > I have a working orthogonal slice viewer here: > https://github.com/jni/mpl-volume-viewer/ > > The problem I have now is that, if I set a mouse-click callback (this line > > and this line > ), > and then I select any other tool from the toolbar, I get this > super-obnoxious flickering, recorded here (macOS 10.12, Tk backend): > https://www.dropbox.com/s/qvfmgp0x36p6rb9/mpl-click-bug.mov?dl=0 > > To reproduce: > > - Download slice_view.py and put it in your PYTHONPATH or current working > directory > - Download this example dataset: > https://www.dropbox.com/s/dj3oarx7bqx4us2/E_z2_512_1um_CONTROL.tif?dl=1 > - Run this code: > > *import matplotlib* > *matplotlib.use('TkAgg')* > > *from skimage import io* > *import slice_view as sv* > > *filename = '/path/to/E_z2_512_1um_CONTROL.tif'* > *image = io.imread(filename) / 4096* > > *v = sv.SliceViewer(image, spacing=[5, 1, 1])* > *matplotlib.pyplot.show(block=True)* > > Questions: > 1) Any ideas about how to fix the flickering? > 2) Is there a cross-backend way to add buttons to the toolbar? All the > examples I've found online were backend-specific. (This way I could at > least disable the callback at will.) > > Thanks! > > Juan. > > On 16 May 2017, 1:43 AM +1000, Thomas Caswell , wrote: > > There are callbacks that fire when the limits are changed. See > > https://matplotlib.org/examples/event_handling/viewlims.html > > for an example. > > This is probably the best route to go down as you can do other interesting > things as the event goes by (like triggering computation, updating a openGL > view window, etc) as well as updating the Matplotlib limits. > > Tom > > On Mon, May 15, 2017 at 3:29 AM Juan Nunez-Iglesias > wrote: > >> Hello, >> >> I?m trying to build an orthogonal-views volume viewer in Matplotlib like >> this one: >> https://imagej.nih.gov/ij/docs/guide/images/OrthogonalViews.png >> >> For this to work, I need to share the y-axis of the YZ (right) >> view/subplot with the x-axis of the XZ (bottom) view/subplot. Is this >> possible? >> >> Juan. >> >> _______________________________________________ >> 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: