SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S






1
2
3
(3)
4
(6)
5
(5)
6
(5)
7
8
9
(1)
10
(5)
11
(11)
12
(6)
13
(6)
14
(4)
15
(1)
16
(1)
17
(10)
18
(20)
19
(5)
20
(7)
21
(1)
22
23
24
25
(1)
26
(3)
27
(1)
28
29
(1)
30
(2)
31
(3)





Showing results of 108

<< < 1 2 3 4 5 > >> (Page 3 of 5)
From: Andre' Walker-L. <wal...@gm...> - 2012年12月17日 18:34:46
Hi Bob,
> I am a matplotlib.pyplot novice, but I have looked through various FAQs to no avail.
> 
> I am plotting a polar graph with some negative values of r. Everything goes well until I try to use rgrids(). Am I doing something wrong?
> 
> I attach some demo scripts and their outputs.
> 
> version1.py uses rgrid() but only has positive values of r. Everything works the way I expect it to (see version1.png).
> 
> version2.py has negative values of r and the same call to rgrid() and misbehaves (see version2.png).
> 
> version3.py is the same as version2.py, but without the call to rgrids() (but with negative values of r). Again everything is as expected.
> 
> What am I doing wrong in version2.py?
I am not sure why things work in version 3 and do not work in version 2. A guess would be how matplotlib is covering up illegal values of your "r" coordinate. Here I am only speaking from the math point of view, and not what is actually happening in matplotlib. I tired finding info in the docs, but did not succeed in getting 
The coordinates "t" and "r" are angle and radius. In polar coordinates, negative values of the radial coordinate "r" are not well defined, since in this coordinate system, you can not have negative values of a radius.
So my **guess** is that your problems are related to this ill definition of the radial coordinate. And that sometimes matplotlib can cover it up for you, and other times it complains more loudly.
Regards,
Andre
I am a matplotlib.pyplot novice, but I have looked through various FAQs 
to no avail.
I am plotting a polar graph with some negative values of r. Everything 
goes well until I try to use rgrids(). Am I doing something wrong?
I attach some demo scripts and their outputs.
version1.py uses rgrid() but only has positive values of r. Everything 
works the way I expect it to (see version1.png).
version2.py has negative values of r and the same call to rgrid() and 
misbehaves (see version2.png).
version3.py is the same as version2.py, but without the call to rgrids() 
(but with negative values of r). Again everything is as expected.
What am I doing wrong in version2.py?
From: Benjamin R. <ben...@ou...> - 2012年12月17日 15:18:35
On Sun, Dec 16, 2012 at 8:22 PM, Diego Avesani <die...@gm...>wrote:
> dear all,
> I have plot a 3D picture, I would like to have xy projection with contours
> levels and labels.
> The contours works but I do not get the labels.
>
> This is my code:
>
> import matplotlib.pyplot as plt
>
> from mpl_toolkits.mplot3d import axes3d, Axes3D
>
> fig = plt.figure()
>
> ax = Axes3D(fig) #<-- Note the difference from your original code...
>
>
> X, Y, Z = axes3d.get_test_data(0.05)
>
>
> cset = ax.contour(X, Y, Z,100,zdir='z',offset=-100)
>
> ax.clabel(cset, fontsize=9, inline=1)
>
>
> plt.show()import matplotlib.pyplot as plt
>
> from mpl_toolkits.mplot3d import axes3d, Axes3D #<-- Note the
> capitalization!
>
> fig = plt.figure()
>
>
> ax = Axes3D(fig) #<-- Note the difference from your original code...
>
>
> X, Y, Z = axes3d.get_test_data(0.05)
>
>
> cset = ax.contour(X, Y, Z,100,zdir='z',offset=-100)
>
> ax.clabel(cset, fontsize=9, inline=1)
>
>
> plt.show()
>
>
> Is it possible to have also the labels?
>
> Thanks
>
>
> Diego
>
>
Theoretically, yes. I have just never thought about that sort of feature
before, and it would not be trivial to implement. In the meantime, you can
take a look at this example for a way to manually label things in a 3d plot.
http://matplotlib.org/examples/mplot3d/text3d_demo.html
Ben Root
From: Diego A. <die...@gm...> - 2012年12月17日 01:22:21
dear all,
I have plot a 3D picture, I would like to have xy projection with contours
levels and labels.
The contours works but I do not get the labels.
This is my code:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d, Axes3D
fig = plt.figure()
ax = Axes3D(fig) #<-- Note the difference from your original code...
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contour(X, Y, Z,100,zdir='z',offset=-100)
ax.clabel(cset, fontsize=9, inline=1)
plt.show()import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d, Axes3D #<-- Note the
capitalization!
fig = plt.figure()
ax = Axes3D(fig) #<-- Note the difference from your original code...
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contour(X, Y, Z,100,zdir='z',offset=-100)
ax.clabel(cset, fontsize=9, inline=1)
plt.show()
Is it possible to have also the labels?
Thanks
Diego
From: David H. <dav...@gm...> - 2012年12月16日 21:41:57
Hi all,
I'm wondering if anyone knows how to compute colorbar limits (vmin, vmax)
based only on the visible portion of the figure. My use-case is a
pcolormesh(x, y, z) drawn over a Basemap instance. The coordinates x and y
cover the entire globe, but I'm only mapping the Arctic. What happens is
that the normalization is done over the entire z array, while only a subset
of z actually appears on the map. The colors appearing on the map thus
cover only a small fraction of the entire color range.
>From what I managed to understand, pcolormesh creates a collections of
patches colorcoded based on the array attribute. So my question is if there
is a builtin way to know which items of this collections are clipped so I
can mask this part of the array ?
Thanks a lot,
David
From: gsal <sal...@gm...> - 2012年12月15日 23:48:18
Say, I am using:
from mpl_toolkits.axes_grid.axislines import SubplotZero
Like this:
fig = plt.figure()
ax1 = SubplotZero(fig,111)
fig.add_subplot(ax1)
ax1.axis["xzero"].set_axisline_style("-|>")
ax1.axis["xzero"].set_visible(True)
ax1.axis["yzero"].set_visible(False)
Now, I would like to set the x axis tick labels to actually "increase" in
the positive as well as the negative directions...How to do that? I can't
even seem to find the xticklabels in this object, in the first place.
Please advise.
Germán 
--
View this message in context: http://matplotlib.1069221.n5.nabble.com/SubplotZero-with-xticklabels-increasing-in-both-directions-tp40033.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Russell E. O. <ro...@uw...> - 2012年12月14日 22:59:09
It turns out I won't be able to make a Mac binary installer for 
matplotlib anytime soon. I use bdist_mpkg to make the Mac binary 
installers for MacOS X, and the current release of bdist_mpkg (4.4) is 
not compatible with Python 3. I don't know how to make binary installers 
without bdist_mpkg, though I'm sure it can be done.
Also note that there are no numpy binary installers for MacOS X python 
3. This *may* be due to the same issue.
Fortunately, it is very easy to install matplotlib from source (much 
easier than it used to be, thanks to patching setupext.py for darwin).
-- Russell
From: Ethan G. <eth...@gm...> - 2012年12月14日 14:51:21
Hi Neal, my understanding is that matplotlib does not use OpenGL (thus
the terrible performance you see). You might want to look into glumpy
for mplot3d OpenGL acceleration.
Ethan
On Dec 14, 2012, at 5:23 AM, Neal Becker <ndb...@gm...> wrote:
> I'm using fedora (17) linux. I notice on complicated 3d plot, interactive
> performance can get sluggish. I'm using nouveau driver now, but wondering if
> installing nvidia driver will improve mpl 3d performance? Does mpl use opengl?
>
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: p.bingham <p.b...@ke...> - 2012年12月14日 13:55:46
I've created a class that allows a user to add several charts to a MATPLOTLIB
window. These can be either a line chart or a bar chart. It also has the
feature that when a chart has already been added to the window (as
identified from rowID) rather than draw a new plot it will replace the data
in the old plot. ie it allows for updates (animation) 
This works grand for the line plot but I get corruption when plotting
several bar charts. The class looks like:
 import math
 class TFrmPlot():
 def __init__(self, point_lists, deleteCallback, plotType, rowID): 
 import matplotlib 
 matplotlib.interactive( True )
 matplotlib.use( 'WXAgg' ) 
 import matplotlib.pyplot as plt
 self.plt = plt
 self.fig = plt.figure() 
 self.fig.canvas.mpl_connect('close_event', self.on_close) 
 import matplotlib.axes as ax 
 self.ax = ax
 self.deleteCallback = deleteCallback
 self.chartArray = [] 
 self.addChart(point_lists, plotType, rowID)
 def close(self): 
 self.plt.close('all')
 #self.fig.close()
 def replaceChartDataIfChartExists(self, point_lists, rowID):
 if rowID==0:
 pass
 for chart in self.chartArray:
 for plot in chart.plots:
 if plot.rowID == rowID:
 plot.points = point_lists 
 if plot.plotType=="Point": 
 
plot.plotItem.set_data(point_lists[0],point_lists[1]) 
 chart.subPlot.draw_artist(plot.plotItem) 
 self.fig.canvas.blit(chart.subPlot.bbox) 
 else: 
 for rect, h in zip(plot.plotItem,
point_lists[1]):
 rect.set_height(h) 
 chart.subPlot.relim() 
 chart.subPlot.autoscale_view(True,True,True) 
 self.plt.draw()
 return True
 return False 
 def addChart(self, point_lists, plotType, rowID):
 self.chartArray.append(TChart(rowID,plotType,point_lists))
 self._drawAll() 
 def addPlot(self, point_lists, plotType, rowID): 
 chartNum = len(self.chartArray)
 
self.chartArray[chartNum-1].plots.append(TPlot(rowID,plotType,point_lists)) 
 self._drawAll()
 def on_close(self, event):
 self.deleteCallback()
 def _drawAll(self): 
 self.plt.clf()
 numSubPlots = len(self.chartArray)
 numCols = self._noCols(numSubPlots)
 IndexConverter = TIndexConverter(numCols)
 subPlot = None
 for chartIndex in range(0,numSubPlots):
 if numSubPlots==1: 
 subPlot = self.fig.add_subplot(1,1,1)
 elif numSubPlots==2: 
 subPlot = self.fig.add_subplot(1,2,chartIndex+1)
 else:
 subPlot =
self.fig.add_subplot(2,numCols,IndexConverter._getSubPlotIndex(chartIndex))
 subPlot.relim() 
 subPlot.autoscale_view(True,True,True)
 self.chartArray[chartIndex].subPlot = subPlot
 self._drawSubs(self.chartArray[chartIndex]) 
 self.plt.show() 
 def _drawSubs(self, chart):
 for plot in chart.plots:
 if plot.plotType=="Point": 
 chart.subPlot.plot(plot.points[0],plot.points[1])
 plot.plotItem =
chart.subPlot.lines[len(chart.subPlot.lines)-1]
 else:
 kwargs = {"alpha":0.5}
 plot.plotItem =
chart.subPlot.bar(plot.points[0],plot.points[1],
width=self._calculateleastDiff(plot.points[0]), **kwargs) 
 def _noCols(self, numSubPlots):
 return math.ceil(float(numSubPlots)/2.0) 
 def _calculateleastDiff(self, xValues):
 xValues2 = sorted(xValues)
 leastDiff = None
 lastValue = None
 for value in xValues2:
 if lastValue is not None: 
 diff = value-lastValue 
 if leastDiff is None or diff < leastDiff:
 leastDiff = diff
 lastValue = value 
 return leastDiff
This is a bit long so to summarise:
addChart -- basically adds a new subplot
addPlot -- adds a new line or bar to an existing subplot
replaceChartDataIfChartExists -- refreshes the data if the ID already exists
The dummy data that I'm using just plots a positive gradient and a negative
gradient line in succession. My plots however can get into a state where
one/some or all of the bar plots become corrupted. It looks almost like the
x/y axis has been rotated, with the individual bars not starting from the
x-axis. The issue is intermittent; sometimes I will get several plots as
expected. Once a plot becomes corrupted all future updates remain corrupted.
Corrupted Chart:
<http://matplotlib.1069221.n5.nabble.com/file/n40023/corrupted.png> 
--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Bar-chart-corruption-when-plotting-multiple-subplots-in-MATPLOTLIB-tp40023.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Neal B. <ndb...@gm...> - 2012年12月14日 12:21:22
I'm using fedora (17) linux. I notice on complicated 3d plot, interactive 
performance can get sluggish. I'm using nouveau driver now, but wondering if 
installing nvidia driver will improve mpl 3d performance? Does mpl use opengl?
From: Steven B. <bo...@ph...> - 2012年12月13日 18:00:58
I echo using the AxesGrid object from the toolkits. Protip -- I have had 
trouble making it work with semilog plots. So if that is what you are 
doing, it might be worth trying another thing or two first.
Steven
On 12/13/12 9:56 AM, Benjamin Root wrote:
>
>
> On Thu, Dec 13, 2012 at 10:45 AM, Claus <cla...@gm... 
> <mailto:cla...@gm...>> wrote:
>
> Hi,
>
> I am trying to plot a colorbar next to each subplot in a figure.
> In the following example, I create two figures. In the second
> figure, I try to add the colorbars. Is there a way to show the
> colorbar next to each subplot. The way I did it, all the colorbars
> appear next to the last subplot, take away space from it, and all
> are plotted using the "jet" colormap.
> Unfortunately, I am not sure how to do this better, and would
> appreciate hints.
>
>
> import numpy as np
> import matplotlib.pylab as plt
>
> def main():
>
> # four subplots, no colorbar, so far so good
> f, axarr = plt.subplots(2, 2)
> axarr[0, 0].imshow(np.random.rand(5,5)*10)
> axarr[0, 1].imshow(np.random.rand(5,5))
> axarr[1, 0].imshow(np.random.rand(5,5)*100)
> axarr[1, 1].imshow(np.random.rand(5,5)*1000)
> plt.show()
>
> # four subplots, four colorbars
> f, axarr = plt.subplots(2, 2)
> a = axarr[0, 0].imshow(np.random.rand(5,5)*10)
> cbar1 = f.colorbar(a, cmap='jet')
> b = axarr[0, 1].imshow(np.random.rand(5,5))
> cbar2 = f.colorbar(b, cmap='Reds')
> c = axarr[1, 0].imshow(np.random.rand(5,5)*100)
> cbar2 = f.colorbar(c, cmap='Blues')
> d = axarr[1, 1].imshow(np.random.rand(5,5)*1000)
> cbar2 = f.colorbar(d, cmap='Greens')
> plt.show()
>
> if __name__ == '__main__':
> main()
>
>
> I think you are looking for the AxesGrid object from the 
> mpl_toolkits.axes_grid1 module:
>
> http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axes-grid1
>
> Ben Root
>
>
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
-- 
Steven Boada
Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
bo...@ph...
From: Sterling S. <sm...@fu...> - 2012年12月13日 16:11:31
Claus,
f.colorbar may be trying to place the colorbar on the 'current axes'. Does placing 
plt.axes(axarr[0,0])
before each f.colorbar help? Also, the plt.colorbar function [1] (maybe f.colorbar also) can take a keyword argument for the axes in which to draw the colorbar.
-Sterling
[1] http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.colorbar
On Dec 13, 2012, at 7:45AM, Claus wrote:
> Hi,
> 
> I am trying to plot a colorbar next to each subplot in a figure. In the following example, I create two figures. In the second figure, I try to add the colorbars. Is there a way to show the colorbar next to each subplot. The way I did it, all the colorbars appear next to the last subplot, take away space from it, and all are plotted using the "jet" colormap.
> Unfortunately, I am not sure how to do this better, and would appreciate hints.
> 
> 
> import numpy as np
> import matplotlib.pylab as plt
> 
> def main():
> 
> # four subplots, no colorbar, so far so good
> f, axarr = plt.subplots(2, 2)
> axarr[0, 0].imshow(np.random.rand(5,5)*10)
> axarr[0, 1].imshow(np.random.rand(5,5))
> axarr[1, 0].imshow(np.random.rand(5,5)*100)
> axarr[1, 1].imshow(np.random.rand(5,5)*1000)
> plt.show()
> 
> # four subplots, four colorbars
> f, axarr = plt.subplots(2, 2)
> a = axarr[0, 0].imshow(np.random.rand(5,5)*10)
> cbar1 = f.colorbar(a, cmap='jet')
> b = axarr[0, 1].imshow(np.random.rand(5,5))
> cbar2 = f.colorbar(b, cmap='Reds')
> c = axarr[1, 0].imshow(np.random.rand(5,5)*100)
> cbar2 = f.colorbar(c, cmap='Blues')
> d = axarr[1, 1].imshow(np.random.rand(5,5)*1000)
> cbar2 = f.colorbar(d, cmap='Greens')
> plt.show()
> 
> if __name__ == '__main__':
> main()
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Benjamin R. <ben...@ou...> - 2012年12月13日 15:57:21
On Thu, Dec 13, 2012 at 10:45 AM, Claus <cla...@gm...> wrote:
> Hi,
>
> I am trying to plot a colorbar next to each subplot in a figure. In the
> following example, I create two figures. In the second figure, I try to add
> the colorbars. Is there a way to show the colorbar next to each subplot.
> The way I did it, all the colorbars appear next to the last subplot, take
> away space from it, and all are plotted using the "jet" colormap.
> Unfortunately, I am not sure how to do this better, and would appreciate
> hints.
>
>
> import numpy as np
> import matplotlib.pylab as plt
>
> def main():
>
> # four subplots, no colorbar, so far so good
> f, axarr = plt.subplots(2, 2)
> axarr[0, 0].imshow(np.random.rand(5,5)*10)
> axarr[0, 1].imshow(np.random.rand(5,5))
> axarr[1, 0].imshow(np.random.rand(5,5)*100)
> axarr[1, 1].imshow(np.random.rand(5,5)*1000)
> plt.show()
>
> # four subplots, four colorbars
> f, axarr = plt.subplots(2, 2)
> a = axarr[0, 0].imshow(np.random.rand(5,5)*10)
> cbar1 = f.colorbar(a, cmap='jet')
> b = axarr[0, 1].imshow(np.random.rand(5,5))
> cbar2 = f.colorbar(b, cmap='Reds')
> c = axarr[1, 0].imshow(np.random.rand(5,5)*100)
> cbar2 = f.colorbar(c, cmap='Blues')
> d = axarr[1, 1].imshow(np.random.rand(5,5)*1000)
> cbar2 = f.colorbar(d, cmap='Greens')
> plt.show()
>
> if __name__ == '__main__':
> main()
>
I think you are looking for the AxesGrid object from the
mpl_toolkits.axes_grid1 module:
http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axes-grid1
Ben Root
From: Claus <cla...@gm...> - 2012年12月13日 15:46:37
Hi,
I am trying to plot a colorbar next to each subplot in a figure. In the following example, I create two figures. In the second figure, I try to add the colorbars. Is there a way to show the colorbar next to each subplot. The way I did it, all the colorbars appear next to the last subplot, take away space from it, and all are plotted using the "jet" colormap.
Unfortunately, I am not sure how to do this better, and would appreciate hints.
import numpy as np
import matplotlib.pylab as plt
def main():
 
 # four subplots, no colorbar, so far so good
 f, axarr = plt.subplots(2, 2)
 axarr[0, 0].imshow(np.random.rand(5,5)*10)
 axarr[0, 1].imshow(np.random.rand(5,5))
 axarr[1, 0].imshow(np.random.rand(5,5)*100)
 axarr[1, 1].imshow(np.random.rand(5,5)*1000)
 plt.show()
 # four subplots, four colorbars
 f, axarr = plt.subplots(2, 2)
 a = axarr[0, 0].imshow(np.random.rand(5,5)*10)
 cbar1 = f.colorbar(a, cmap='jet')
 b = axarr[0, 1].imshow(np.random.rand(5,5))
 cbar2 = f.colorbar(b, cmap='Reds')
 c = axarr[1, 0].imshow(np.random.rand(5,5)*100)
 cbar2 = f.colorbar(c, cmap='Blues')
 d = axarr[1, 1].imshow(np.random.rand(5,5)*1000)
 cbar2 = f.colorbar(d, cmap='Greens')
 plt.show()
if __name__ == '__main__':
 main()
From: Benjamin R. <ben...@ou...> - 2012年12月13日 14:47:09
On Mon, Dec 10, 2012 at 5:49 PM, Timothy Duly <tim...@gm...> wrote:
> Paul,
>
> Actually, I didn't realize that you had to change the backend in the
> matplotlibrc file. Once I changed it to 'Qt4Agg', everything worked.
> Thanks!
>
> (to find out where your matplotlibrc file is:
> "matplotlib.matplotlib_fname()" )
>
> Tim
>
>
>
Usually, you don't have to, but I guess something happened with your
install at some point that messed around with your rc file. Glad to see it
fixed.
Ben Root
From: Forrester, K. <kur...@gm...> - 2012年12月13日 06:49:48
Thank you Paul. That is exactly it. I guess I was confused by the example
in the help. The addition of your example would be a great addition to the
help file.
Kurt
On 12 December 2012 23:56, Paul Hobson <pmh...@gm...> wrote:
>
>
> On Wed, Dec 12, 2012 at 7:55 AM, Forrester, Kurt <
> kur...@gm...> wrote:
>
>> ax.set_xlim(0.5, 2)
>> ax.set_xscale('log', basex=2, subsx=range(2,9))
>>
>
>
> Kurt,
>
> That `subsx` kwarg is tricky. Does this example get you closer to what you
> want?
>
> import numpy as np
> import matplotlib.pyplot as plt
> fig, ax = plt.subplots()
> ax.set_xlim(0.5, 10)
> ax.set_xscale('log', basex=2, subsx=np.arange(1.,2.1,0.1))
> ax.xaxis.grid(True, which='minor')
> plt.show()
>
> -paul
>
From: Paul H. <pmh...@gm...> - 2012年12月12日 23:56:45
On Wed, Dec 12, 2012 at 7:55 AM, Forrester, Kurt <
kur...@gm...> wrote:
> ax.set_xlim(0.5, 2)
> ax.set_xscale('log', basex=2, subsx=range(2,9))
>
Kurt,
That `subsx` kwarg is tricky. Does this example get you closer to what you
want?
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_xlim(0.5, 10)
ax.set_xscale('log', basex=2, subsx=np.arange(1.,2.1,0.1))
ax.xaxis.grid(True, which='minor')
plt.show()
-paul
From: Forrester, K. <kur...@gm...> - 2012年12月12日 15:55:19
I cannot seem to get the following code produce what I expect. I want minor
tick marks between my major ticks on a base 2 logx plot.
ax = axes()
ax.set_xlim(0.5, 2)
ax.set_xscale('log', basex=2, subsx=range(2,9))
grid(b=True, which='minor')
I would have expected there to be minor ticks at 2^(-1:0.1:1) excluding
-1,0 and 1. Any help would be appreciated.
Kind regards,
Kurt
From: Jason G. <jas...@cr...> - 2012年12月12日 14:51:13
Hi everyone,
Just FYI, IPython just received 1ドル.15 million in funding from the Alfred 
P. Sloan Foundation to support development over the next 2 years. 
Fernando talks more about this in his post to the IPython mailing list:
http://mail.scipy.org/pipermail/ipython-dev/2012-December/010799.html
It's great to see a significant open-source python project that many of 
us use on a day-to-day basis get such great funding!
Thanks,
Jason
--
Jason Grout
From: David Yu <zhi...@gm...> - 2012年12月12日 11:46:47
Greetings,
With the help of sankey-toolbox, we can plot sankey-diagrams automaticly:
The position of a sankey-object is automaticly calculated based on the
position of its prior-object and cannot be given manually; and when a
sankey-diagram is initialized, the position of the first sankey-object will
be assigned with the input of an axis. (the (0,0)-point will be the
center-point of this object)
And Here is the situation: i want to draw two sankey-diagrams in the same
subplot with a given y-offset, therefore are two coordinate systems with
y-offset required. I have tried the 'add_axes' method, but with this method
a new subplot is created and there will be a graphic scaling problem.
Now this is the question: Is it possible to create a new coordinate system
with a given y-offset, without creating new subplot?
--
View this message in context: http://matplotlib.1069221.n5.nabble.com/create-an-new-axis-with-y-offset-in-the-same-subplot-tp40006.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Eric F. <ef...@ha...> - 2012年12月12日 06:08:49
On 2012年12月11日 1:24 PM, Timothy Duly wrote:
> Thanks Eric, this did the trick. I did not know such a thing existed.
> Why "4"?
I don't remember exactly what the defaults are for different types of 
artist, and didn't want to take the time to look, but I think they are 
all less than 4. So I just picked that as a value that would do the job.
Eric
>
> Tim
>
>
> On Tue, Dec 11, 2012 at 4:35 PM, Eric Firing <ef...@ha...
> <mailto:ef...@ha...>> wrote:
>
> On 2012年12月11日 12:16 PM, Timothy Duly wrote:
> > Hi,
> >
> > I'm running into a problem with overlaying a scatter plot on a
> polygon
> > that is on a Basemap. The polygon covers up the scatter plot
> created by
> > the basemap. To show the issue, the simple example below and broken
> > down into three steps: 1) creating the map, 2) adding the red
> polygon,
> > and 3) adding the "x" markers via a scatter plot. You will see
> that the
> > "x" markers are not on top of the polygon.
> >
> > Why does the polygon cover up the markers, even though I have the
> > markers added after the polygon? Would there be a better way to do
> > this? I could set the polygon alpha to, say, 0.5, but this
> feature does
> > not show when I save it as an eps image. Therefore, I would like to
> > keep alpha=1.
>
> Artists have a zorder attribute that controls the drawing order. Try
> adding the kwarg zorder=4 to your scatter call. I think that will take
> care of it. (Alternatively you could lower the zorder of the polygon.)
>
> Eric
>
> >
> > Thanks,
> > Tim
> >
> > from mpl_toolkits.basemap import Basemap
> > import numpy as np
> > from matplotlib.pyplot import *
> > from matplotlib.patches import Polygon
> >
> >
> > # ---------------------
> > # Part 1: Draw the map
> > # ---------------------
> >
> > # Hawaii:
> > lat_0 = 20.71-8.
> > lon_0 = 203.83
> >
> > figure(1); clf();
> > m = Basemap(width=2500e3,height=2500e3,
> > resolution='l',projection='stere', \
> > lat_ts=lat_0,lat_0=lat_0,lon_0=lon_0)
> >
> > m.drawcoastlines()
> > m.fillcontinents(color='coral',lake_color='aqua')
> >
> > # draw parallels and meridians:
> > m.drawmapboundary(fill_color='aqua')
> >
> > lats = np.arange(np.floor(m.latmin),np.ceil(m.latmax),2.)
> > lons = np.arange(190.,211.,5.)
> > m.drawparallels(lats,labels=[True,False,False,False])
> > m.drawmeridians(lons,labels=[False,False,False,True])
> >
> > draw(); show()
> >
> > # ---------------------
> > # Part 2: Add a polygon
> > # ---------------------
> >
> > lon_poly = np.array([-160., -150., -150., -160.,])
> > lat_poly = np.array([10., 10., 14., 14.,])
> > X, Y = m(lon_poly, lat_poly)
> > xy = np.vstack([X,Y]).T
> >
> > poly = Polygon(xy, closed=True, \
> > facecolor='red', \
> > linewidth=1., \
> > )
> >
> > gca().add_patch(poly)
> >
> > # ---------------------
> > # Part 3: add some 'x' markers
> > # ---------------------
> >
> > lon_markers = np.arange(-168.,-144.,2.)
> > lat_markers = np.arange(5.,20.,1.)
> > X, Y = np.meshgrid(lon_markers, lat_markers)
> >
> > x, y = m(X.ravel(), Y.ravel())
> > m.scatter(x,y,marker='x')
> >
> > draw(); show()
> >
> >
> >
> >
> ------------------------------------------------------------------------------
> > LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> > Remotely access PCs and mobile devices and provide instant support
> > Improve your efficiency, and focus on delivering more value-add
> services
> > Discover what IT Professionals Know. Rescue delivers
> > http://p.sf.net/sfu/logmein_12329d2d
> >
> >
> >
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> <mailto:Mat...@li...>
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> <mailto:Mat...@li...>
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
From: Damon M. <dam...@gm...> - 2012年12月12日 00:59:21
On Tue, Dec 11, 2012 at 1:16 PM, Benjamin Root <ben...@ou...> wrote:
>
>
> On Tue, Dec 11, 2012 at 2:08 PM, Chloe Lewis <ch...@be...> wrote:
>>
>> Would it be workable for the default to be proportional to the size of the
>> array passed in? (suggested only because I do that myself, when deciding how
>> coarse an investigative plot I can get away with.)
>>
>> &C
>>
>
> That is pretty much what the PR I was referring to does:
>
> https://github.com/matplotlib/matplotlib/pull/1040
>
> It makes it so that the behavior of both plot_surface and plot_wireframe is
> the same in this respect. So, by default, the rstride and cstride would be
> 1% of the size of your data array. This would make the default for the
> recent example be 1, therefore showing every point. I wonder if a
> logarithmic default would make sense to better handle large data arrays?
>
> Thoughts?
> Ben Root
I hope nobody minds if I chime in here.
I'm in favour of making the defaults a little more intelligent that
what is implemented at present, i.e, a constant stride for any
surface. Any non-trivial scaling law to determine what stride to use
will result in more expected behaviour than what our users are
currently seeing.
Could we do better? Could we have plot_surface try and estimate the
stride based on the 'roughness' of the surface to be plotted? This
method would grind to a halt for very rough surfaces, so we could
default to a scaling law in these cases.
What does everyone think about this approach?
-- 
Damon McDougall
http://www.damon-is-a-geek.com
Institute for Computational Engineering Sciences
201 E. 24th St.
Stop C0200
The University of Texas at Austin
Austin, TX 78712-1229
From: Timothy D. <tim...@gm...> - 2012年12月11日 23:24:26
Thanks Eric, this did the trick. I did not know such a thing existed. Why
"4"?
Tim
On Tue, Dec 11, 2012 at 4:35 PM, Eric Firing <ef...@ha...> wrote:
> On 2012年12月11日 12:16 PM, Timothy Duly wrote:
> > Hi,
> >
> > I'm running into a problem with overlaying a scatter plot on a polygon
> > that is on a Basemap. The polygon covers up the scatter plot created by
> > the basemap. To show the issue, the simple example below and broken
> > down into three steps: 1) creating the map, 2) adding the red polygon,
> > and 3) adding the "x" markers via a scatter plot. You will see that the
> > "x" markers are not on top of the polygon.
> >
> > Why does the polygon cover up the markers, even though I have the
> > markers added after the polygon? Would there be a better way to do
> > this? I could set the polygon alpha to, say, 0.5, but this feature does
> > not show when I save it as an eps image. Therefore, I would like to
> > keep alpha=1.
>
> Artists have a zorder attribute that controls the drawing order. Try
> adding the kwarg zorder=4 to your scatter call. I think that will take
> care of it. (Alternatively you could lower the zorder of the polygon.)
>
> Eric
>
> >
> > Thanks,
> > Tim
> >
> > from mpl_toolkits.basemap import Basemap
> > import numpy as np
> > from matplotlib.pyplot import *
> > from matplotlib.patches import Polygon
> >
> >
> > # ---------------------
> > # Part 1: Draw the map
> > # ---------------------
> >
> > # Hawaii:
> > lat_0 = 20.71-8.
> > lon_0 = 203.83
> >
> > figure(1); clf();
> > m = Basemap(width=2500e3,height=2500e3,
> > resolution='l',projection='stere', \
> > lat_ts=lat_0,lat_0=lat_0,lon_0=lon_0)
> >
> > m.drawcoastlines()
> > m.fillcontinents(color='coral',lake_color='aqua')
> >
> > # draw parallels and meridians:
> > m.drawmapboundary(fill_color='aqua')
> >
> > lats = np.arange(np.floor(m.latmin),np.ceil(m.latmax),2.)
> > lons = np.arange(190.,211.,5.)
> > m.drawparallels(lats,labels=[True,False,False,False])
> > m.drawmeridians(lons,labels=[False,False,False,True])
> >
> > draw(); show()
> >
> > # ---------------------
> > # Part 2: Add a polygon
> > # ---------------------
> >
> > lon_poly = np.array([-160., -150., -150., -160.,])
> > lat_poly = np.array([10., 10., 14., 14.,])
> > X, Y = m(lon_poly, lat_poly)
> > xy = np.vstack([X,Y]).T
> >
> > poly = Polygon(xy, closed=True, \
> > facecolor='red', \
> > linewidth=1., \
> > )
> >
> > gca().add_patch(poly)
> >
> > # ---------------------
> > # Part 3: add some 'x' markers
> > # ---------------------
> >
> > lon_markers = np.arange(-168.,-144.,2.)
> > lat_markers = np.arange(5.,20.,1.)
> > X, Y = np.meshgrid(lon_markers, lat_markers)
> >
> > x, y = m(X.ravel(), Y.ravel())
> > m.scatter(x,y,marker='x')
> >
> > draw(); show()
> >
> >
> >
> >
> ------------------------------------------------------------------------------
> > LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> > Remotely access PCs and mobile devices and provide instant support
> > Improve your efficiency, and focus on delivering more value-add services
> > Discover what IT Professionals Know. Rescue delivers
> > http://p.sf.net/sfu/logmein_12329d2d
> >
> >
> >
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>
>
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Eric F. <ef...@ha...> - 2012年12月11日 22:34:22
On 2012年12月11日 12:16 PM, Timothy Duly wrote:
> Hi,
>
> I'm running into a problem with overlaying a scatter plot on a polygon
> that is on a Basemap. The polygon covers up the scatter plot created by
> the basemap. To show the issue, the simple example below and broken
> down into three steps: 1) creating the map, 2) adding the red polygon,
> and 3) adding the "x" markers via a scatter plot. You will see that the
> "x" markers are not on top of the polygon.
>
> Why does the polygon cover up the markers, even though I have the
> markers added after the polygon? Would there be a better way to do
> this? I could set the polygon alpha to, say, 0.5, but this feature does
> not show when I save it as an eps image. Therefore, I would like to
> keep alpha=1.
Artists have a zorder attribute that controls the drawing order. Try 
adding the kwarg zorder=4 to your scatter call. I think that will take 
care of it. (Alternatively you could lower the zorder of the polygon.)
Eric
>
> Thanks,
> Tim
>
> from mpl_toolkits.basemap import Basemap
> import numpy as np
> from matplotlib.pyplot import *
> from matplotlib.patches import Polygon
>
>
> # ---------------------
> # Part 1: Draw the map
> # ---------------------
>
> # Hawaii:
> lat_0 = 20.71-8.
> lon_0 = 203.83
>
> figure(1); clf();
> m = Basemap(width=2500e3,height=2500e3,
> resolution='l',projection='stere', \
> lat_ts=lat_0,lat_0=lat_0,lon_0=lon_0)
>
> m.drawcoastlines()
> m.fillcontinents(color='coral',lake_color='aqua')
>
> # draw parallels and meridians:
> m.drawmapboundary(fill_color='aqua')
>
> lats = np.arange(np.floor(m.latmin),np.ceil(m.latmax),2.)
> lons = np.arange(190.,211.,5.)
> m.drawparallels(lats,labels=[True,False,False,False])
> m.drawmeridians(lons,labels=[False,False,False,True])
>
> draw(); show()
>
> # ---------------------
> # Part 2: Add a polygon
> # ---------------------
>
> lon_poly = np.array([-160., -150., -150., -160.,])
> lat_poly = np.array([10., 10., 14., 14.,])
> X, Y = m(lon_poly, lat_poly)
> xy = np.vstack([X,Y]).T
>
> poly = Polygon(xy, closed=True, \
> facecolor='red', \
> linewidth=1., \
> )
>
> gca().add_patch(poly)
>
> # ---------------------
> # Part 3: add some 'x' markers
> # ---------------------
>
> lon_markers = np.arange(-168.,-144.,2.)
> lat_markers = np.arange(5.,20.,1.)
> X, Y = np.meshgrid(lon_markers, lat_markers)
>
> x, y = m(X.ravel(), Y.ravel())
> m.scatter(x,y,marker='x')
>
> draw(); show()
>
>
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Timothy D. <tim...@gm...> - 2012年12月11日 22:16:50
Hi,
I'm running into a problem with overlaying a scatter plot on a polygon that
is on a Basemap. The polygon covers up the scatter plot created by the
basemap. To show the issue, the simple example below and broken down into
three steps: 1) creating the map, 2) adding the red polygon, and 3) adding
the "x" markers via a scatter plot. You will see that the "x" markers are
not on top of the polygon.
Why does the polygon cover up the markers, even though I have the markers
added after the polygon? Would there be a better way to do this? I could
set the polygon alpha to, say, 0.5, but this feature does not show when I
save it as an eps image. Therefore, I would like to keep alpha=1.
Thanks,
Tim
from mpl_toolkits.basemap import Basemap
import numpy as np
from matplotlib.pyplot import *
from matplotlib.patches import Polygon
# ---------------------
# Part 1: Draw the map
# ---------------------
# Hawaii:
lat_0 = 20.71-8.
lon_0 = 203.83
figure(1); clf();
m = Basemap(width=2500e3,height=2500e3,
 resolution='l',projection='stere', \
 lat_ts=lat_0,lat_0=lat_0,lon_0=lon_0)
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians:
m.drawmapboundary(fill_color='aqua')
lats = np.arange(np.floor(m.latmin),np.ceil(m.latmax),2.)
lons = np.arange(190.,211.,5.)
m.drawparallels(lats,labels=[True,False,False,False])
m.drawmeridians(lons,labels=[False,False,False,True])
draw(); show()
# ---------------------
# Part 2: Add a polygon
# ---------------------
lon_poly = np.array([-160., -150., -150., -160.,])
lat_poly = np.array([10., 10., 14., 14.,])
X, Y = m(lon_poly, lat_poly)
xy = np.vstack([X,Y]).T
poly = Polygon(xy, closed=True, \
 facecolor='red', \
 linewidth=1., \
 )
gca().add_patch(poly)
# ---------------------
# Part 3: add some 'x' markers
# ---------------------
lon_markers = np.arange(-168.,-144.,2.)
lat_markers = np.arange(5.,20.,1.)
X, Y = np.meshgrid(lon_markers, lat_markers)
x, y = m(X.ravel(), Y.ravel())
m.scatter(x,y,marker='x')
draw(); show()

Showing results of 108

<< < 1 2 3 4 5 > >> (Page 3 of 5)
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /