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
(16) |
2
(22) |
3
(28) |
4
(17) |
5
(17) |
6
(7) |
7
|
8
(15) |
9
(28) |
10
(26) |
11
(28) |
12
(19) |
13
(5) |
14
(3) |
15
(21) |
16
(28) |
17
(11) |
18
(18) |
19
(6) |
20
(5) |
21
(18) |
22
(11) |
23
(22) |
24
(28) |
25
(17) |
26
(17) |
27
(7) |
28
(16) |
29
(24) |
30
(25) |
31
(14) |
|
|
|
From: Sunman <sun...@gm...> - 2010-03-28 23:51:36
|
Hello, I am trying to use the imshow() function for a 2-dimensional array. However, I am having issues with the following: When the array is perfectly square the image looks like this: http://old.nabble.com/file/p28063442/Plot2.png but when it is not it looks like this: http://old.nabble.com/file/p28063442/Plot.png Is there any way I can line up the image for a rectangular array so that its in the top left corner? Thank you -- View this message in context: http://old.nabble.com/Issues-with-imshow-tp28063442p28063442.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
From: Friedrich R. <fri...@gm...> - 2010-03-28 23:20:01
|
2010/3/29 Alan G Isaac <ala...@gm...>: > OK, it's obvious one you point it out. > Sorry for the typo in the example. > > Now suppose I want a colorbar labelled at -1, 0, 1 > but the highest value realized is <1. Can I somehow > use ticks=(-1,0,1) anyway, or do I have to tick at > the realized limits and then label "falsely". Here's an > example, hopefully without typos this time. > > x = np.linspace(-5, 5, 101) > y = x > Z = np.sin(x*y[:,None]).clip(-1,1-1E-6) > fig = plt.figure() > ax = fig.add_subplot(1,1,1) > cax = ax.imshow(Z, interpolation='nearest', extent=[-5,5,-5,5]) > cbar = fig.colorbar(cax, ticks=(-1, 0, 1)) > > As you see, the top tick is not labelled. On my machine, it /labels/ the +1.0, so I changed the mismatch to the safe-failing (1 - 0.1) value, in the script attached. Also I fixed your problem, hopefully. Friedrich |
From: Alan G I. <ala...@gm...> - 2010-03-28 22:36:50
|
On 3/28/2010 3:04 PM, Ryan May wrote: > it's just using indices, which run from 0 to 99. Since the limits > are 0 to 100, bam...white space because, indeed, there is no data. > OK, it's obvious one you point it out. Sorry for the typo in the example. Now suppose I want a colorbar labelled at -1, 0, 1 but the highest value realized is <1. Can I somehow use ticks=(-1,0,1) anyway, or do I have to tick at the realized limits and then label "falsely". Here's an example, hopefully without typos this time. x = np.linspace(-5, 5, 101) y = x Z = np.sin(x*y[:,None]).clip(-1,1-1E-6) fig = plt.figure() ax = fig.add_subplot(1,1,1) cax = ax.imshow(Z, interpolation='nearest', extent=[-5,5,-5,5]) cbar = fig.colorbar(cax, ticks=(-1, 0, 1)) As you see, the top tick is not labelled. Thanks, Alan |
From: Chloe L. <ch...@be...> - 2010-03-28 20:52:57
|
That would be a lot nicer, Friedrich; could you share demo code? I can't make the set_ylim work, but I think I'm being clumsy with the object model. E.g., from this: |
From: Friedrich R. <fri...@gm...> - 2010-03-28 19:59:21
|
2010/3/28 Ariel Rokem <ar...@be...>: > Hi Chloe, > > _segmentdata - that's what I was looking for! Hmm, much easier would maybe be: colorbar = figure.colorbar(...) colorbar.ax.set_xlim((C.min(), C.max()) # Or .set_ylim() for vertical cbars. I just did a dive into the matplotlib code and docu: http://matplotlib.sourceforge.net/api/colorbar_api.html#matplotlib.colorbar.ColorbarBase It has also the advantage that the xticks represent the correct values. For small C ranges one should consider using a cmap subdivided finer? Friedrich |
From: Ariel R. <ar...@be...> - 2010-03-28 19:44:50
|
Hi Chloe, _segmentdata - that's what I was looking for! Thanks a lot also for that bit of code! Cheers - Ariel On Sun, Mar 28, 2010 at 1:53 AM, Chloe Lewis <ch...@be...> wrote: > Like so, not that it couldn't be improved: > > import matplotlib.cm as cm > import matplotlib.colors as colors > import pylab as p > > def rgb_to_dict(value, cbar): > return dict(zip(('red','green','blue','alpha'), cbar(value))) > > def subcolorbar(xmin, xmax, cbar): > '''Returns the part of cbar between xmin, xmax, scaled to 0,1.''' > assert xmin < xmax > assert xmax <=1 > cd = cbar._segmentdata.copy() > colornames = ('red','green','blue') > rgbmin, rgbmax = rgb_to_dict(xmin, cbar), rgb_to_dict(xmax, cbar) > for k in cd: > tmp = [x for x in cd[k] if x[0] >= xmin and x[0] <= xmax] > if tmp == [] or tmp[0][0] > xmin: > tmp = [(xmin, rgbmin[k], rgbmin[k])] + tmp > if tmp == [] or tmp[-1][0] < xmax: > tmp = tmp + [ (xmax,rgbmax[k], rgbmax[k])] > #now scale all this to (0,1) > square = zip(*tmp) > xbreaks = [(x - xmin)/(xmax-xmin) for x in square[0]] > square[0] = xbreaks > tmp = zip(*square) > cd[k] = tmp > return colors.LinearSegmentedColormap('local', cd, N=256) > > if __name__=="__main__": > subset = [.1, .3, .6] > scb = subcolorbar(min(subset), max(subset), cm.jet) > print 'main segments', cm.jet._segmentdata > print 'smaller', scb._segmentdata > p.subplot(121) > p.scatter([1,2,3],[1,2,3],s=49, c = subset, cmap=scb) > p.colorbar() > p.subplot(122) > p.scatter([2,3,4],[2,3,4],s=49, c =[.001, .5, .99], cmap=cm.jet) > p.colorbar() > p.show() > > > > > On Mar 27, 2010, at 11:52 PM, Chloe Lewis wrote: > > To zoom in on the relevant section of a colorbar -- I convinced myself >> once that I'd need an auxiliary function to define a new cdict that >> covers only the current section of the original cdict. (and then >> define a new colorbar from the cdict, and maybe do a little norming of >> the data). >> >> _segmentdata will give you the original cdict for whichever colorbar >> you're using. >> >> Not that I got around to actually doing it! But it would be great for >> paper readability and passing-around of plots. >> >> &C >> >> >> >> On Mar 27, 2010, at 9:24 PM, Ariel Rokem wrote: >> >> Hi Friedrich, >>> >>> Thanks a lot for your response. I think that you are right - using >>> the vmin/vmax args into imshow (as well as into pcolor) does seem to >>> do what I want. Great! >>> >>> The only thing that remains now is to simultaneously stretch the >>> colormap in the image itself to this range, while also restricting >>> the range of the colorbar which is displayed, to only the part of >>> the colormap which actually has values (in the attached .png, I only >>> want values between 0 and ~0.33 to appear in the colorbar, not from >>> negative -0.33 to +0.33). >>> >>> Does anyone know how to do that? >>> >>> Thanks again - >>> >>> Ariel >>> >>> On Sat, Mar 27, 2010 at 3:29 PM, Friedrich Romstedt < >>> fri...@gm... >>> >>>> wrote: >>>> >>> 2010/3/27 Ariel Rokem <ar...@be...>: >>> >>>> I am trying to make a color-map which will respond to the range of >>>> >>> values in >>> >>>> the data itself. That is - I want to take one of the mpl colormaps >>>> >>> and use >>> >>>> parts of it, depending on the range of the data. >>>> >>>> In particular, I am interested in using the plt.cm.RdYlBu_r >>>> >>> colormap. If the >>> >>>> data has both negative and positive values, I want 0 to map to the >>>> >>> central >>> >>>> value of this colormap (a pale whitish yellow) and I want negative >>>> >>> values to >>> >>>> be in blue and positive numbers to be in red. Also - I would want >>>> >>> to use the >>> >>>> parts of the colormap that represent how far away the smallest and >>>> >>> largest >>> >>>> values in the data are from 0. So - if my data is in the range >>>> >>> [x1,x2] I >>> >>>> would want to use the part of the colormap in indices >>>> 127-127*abs(x1)/(x2-x1) through 127+127*x2/(x2-x1). If the data only >>>> includes positive numbers, I would want to only use the blue part >>>> >>> of the >>> >>>> colormap and if there are negative numbers, I would want to only >>>> >>> use the red >>> >>>> part of the colormap (in these cases, I would also want to take >>>> >>> only a >>> >>>> portion of the colormap which represents the size of the interval >>>> >>> [x1,x2] >>> >>>> relative to the interval [0,x1] or [x2,0], as the case may be). >>>> >>>> I think that this might be useful when comparing matrices >>>> >>> generated from >>> >>>> different data, but with the same computation, such as correlation >>>> >>> or >>> >>>> coherence (see http://nipy.sourceforge.net/nitime/examples/ >>>> >>> fmri.html to get >>> >>>> an idea of what I mean). >>>> >>> >>> I might miss something important, but why not use pcolor() with kwargs >>> vmin and vmax, >>> >>> http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.pcolor >>> , >>> e.g.: >>> >>> maxval = numpy.abs(C).max() >>> pcolor(C, vmin = -maxval, vmax = maxval) >>> >>> As far as I can judge, this should have the desired effect. >>> >>> Friedrich >>> >>> >>> >>> -- >>> Ariel Rokem >>> Helen Wills Neuroscience Institute >>> University of California, Berkeley >>> http://argentum.ucbso.berkeley.edu/ariel >>> < >>> colorbar >>> .png >>> >>>> >>>> ------------------------------------------------------------------------------ >>> Download Intel® Parallel Studio Eval >>> Try the new software tools for yourself. Speed compiling, find bugs >>> proactively, and fine-tune applications for parallel performance. >>> See why Intel Parallel Studio got high marks during beta. >>> >>> http://p.sf.net/sfu/intel-sw-dev_______________________________________________ >>> Matplotlib-users mailing list >>> Mat...@li... >>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >>> >> >> >> >> ------------------------------------------------------------------------------ >> Download Intel® Parallel Studio Eval >> Try the new software tools for yourself. Speed compiling, find bugs >> proactively, and fine-tune applications for parallel performance. >> See why Intel Parallel Studio got high marks during beta. >> http://p.sf.net/sfu/intel-sw-dev >> _______________________________________________ >> Matplotlib-users mailing list >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> > > -- Ariel Rokem Helen Wills Neuroscience Institute University of California, Berkeley http://argentum.ucbso.berkeley.edu/ariel |
From: Friedrich R. <fri...@gm...> - 2010-03-28 19:35:33
|
2010/3/28 Filipe Pires Alvarenga Fernandes <oc...@gm...>: > Hello list > I've trying for a while a "python only" solution to remove white spaces that > Basemap generate to keep the aspect ratio. I found these two threads that > explain the issue better: I think maybe you can make use of the Agg Backend to achieve a Python-only solution to obtain a PIL Image from a figure without bypassing over the HDD: Furthemore, if this doesn't work, maybe you can use a StringIO as "file", then seek() the StringIO and reread with PIL from the "file-like" StringIO, or something like that? # # Render the Figure to a PIL Image ... # # Prepare figure to be of pixel extent *shape* ... dpi = figure.dpi figure.set_size_inches(float(shape[0]) / dpi, float(shape[1]) / dpi) # Create the rendering Canvas ... # # We also convert the picture to an RGB string. canvas = matplotlib.backends.backend_agg.FigureCanvasAgg(figure) canvas.draw() image_string = canvas.tostring_rgb() # Create a PIL Image from RGB string ... image = Image.fromstring("RGB", shape, image_string) # Now do whatever you want with the Image. Friedrich |
From: Ryan M. <rm...@gm...> - 2010-03-28 19:04:31
|
On Sun, Mar 28, 2010 at 11:16 AM, Alan G Isaac <ala...@gm...> wrote: > Using contourf in version 0.99.1, > I'm seeing an unwanted white strip to > the top and right, adjacent to the axes. > (In fact, the strip looks just wide > enough to underlay the ticks.) > > Alan Isaac > > PS Simple example: > > x = np.linspace(-5, 5, 100) > X, Y = np.meshgrid(x, x) > Z = np.sin(x*y[:,None]) > fig = plt.figure() > ax = fig.add_subplot(1,1,1) > ax.contourf(Z) Well, in your simple example you're not even using the X and Y you calculate to give the spatial dimensions of your data, so it's just using indices, which run from 0 to 99. Since the limits are 0 to 100, bam...white space because, indeed, there is no data. If I do the following example, I don't get any whitespace: x = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, x) Z = np.sin(x*x[:,None]) #Note change from bug in previous ex. fig = plt.figure() ax = fig.add_subplot(1,1,1) ax.contourf(X, Y, Z) ax.set_xlim(-5, 5) ax.set_ylim(-5, 5) plt.draw() Is there something I'm missing? (Running SVN trunk here) Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma |
From: Alan G I. <ala...@gm...> - 2010-03-28 17:16:51
|
Using contourf in version 0.99.1, I'm seeing an unwanted white strip to the top and right, adjacent to the axes. (In fact, the strip looks just wide enough to underlay the ticks.) Alan Isaac PS Simple example: x = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, x) Z = np.sin(x*y[:,None]) fig = plt.figure() ax = fig.add_subplot(1,1,1) ax.contourf(Z) |
From: Alan G I. <ala...@gm...> - 2010-03-28 16:47:17
|
1. Sorry if I miss this in the docs, but what are the default values of rstride and cstride? It seems these automagically limit the amount of data used by the surface plot. 2. Also, what is the right way to set alpha for the surface? If I use an alpha keyword for plot_surface, I cannot seem to push the alpha above the default, which looks to be about 0.5. (I can however make the surface more transparent.) 3. In interactive mode, the "Home" button does not seem to restore the original perspective? (TkAgg backend.) Should it? (I'd like it to.) Btw, I really like the surface plots! Thanks, Alan Isaac |
From: Peter B. <bu...@gm...> - 2010-03-28 12:12:51
|
I've done a few minor enhancements and corrections to the qt4_editor (interactive plot options popup). Should I submit them to matplotlib or directly to the original author Pierre Raybaut ? What plot options do you think can be added to the qt4_editor ? I've added a basic Legend option to the Axes tab and a Visible option to the Curves tab. formlayout.py: validate color strings (for matplotlib) figureoptions.py: corrected marker=='none' bug corrected matplotlib green in COLORS ('g': '#008000') missing ',' and incorrect naming of some MARKERS LINESTYLES are sorted. 'steps' removed from linestyles On Sun, Mar 21, 2010 at 5:22 AM, Peter Butterworth wrote: > Correction: '0.99.3rc1' does not include the qt4_editor code, so you > do need to get the source files from svn. > > The feature is a nice addition to matplotlib.. |
From: Rune V. S. <rv...@gm...> - 2010-03-28 11:14:51
|
Hello again, and thanks. I did not have a chance to look at this until now but using arc instead of angle worked out great. 2010/3/24 Jae-Joon Lee <lee...@gm...> > You should not use "angle" style if you change the x,y position (this > is due to the algorithm of how the line connecting two points are > create). > > Try something like below instead. > > if foo: > if theta - foo < 10: > print >>sys.stderr, "Overlapping, offsetting a little bit" > y1 = y1 + 0.1 > if x1 > 0 : > cstyle="arc,angleA=180,armA=30,armB=10,angleB=%f"%(-theta,) > else: > cstyle="arc,angleA=0,armA=30,armB=10,angleB=%f"%(theta,) > > There is not much documentation of how each algorithm works (it is > beyond my english skill). They are loosely based on the latex pstrick > package and the screenshot in the following link may be useful to get > some idea though. > > > http://matplotlib.sourceforge.net/users/annotations_guide.html#annotating-with-arrow > > Regards, > > -JJ > > > 2010/3/24 Rune V. Sjøen <rv...@gm...>: > > Hello again, and thank you very much for the answer, suddenly it all got > > much clearer to me. The only 'issue' I am having is (from screenshot) > what > > happens to the line pointing to Logs when I try to offset it a little bit > on > > the Y axis. It looks like either the angleA or angleB is wrong, but I > don't > > see and reason why it would be as the X coordinates does not change. > > > > Another thing I do not quite understand is what that patchB does. > > > > figure(1, figsize=(6,6)) > > ax = axes([0.1, 0.1, 0.8, 0.8]) > > > > labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' > > fracs = [45, 135 ,1, 1] > > > > p = pie(fracs) > > > > foo = None > > for p1, l1 in zip(p[0], labels): > > > > r = p1.r > > dr = r*0.1 > > t1, t2 = p1.theta1, p1.theta2 > > theta = (t1+t2)/2. > > > > xc = cos(theta/180.*pi)*r > > yc = sin(theta/180.*pi)*r > > x1 = cos(theta/180.*pi)*(r+dr) > > y1 = sin(theta/180.*pi)*(r+dr) > > > > if x1 > 0 : > > x1 = r+2*dr > > ha, va = "left", "center" > > cstyle="angle,angleA=180,angleB=%f"%(-theta,) > > print >> sys.stderr, ha, ",A,", va > > else: > > x1 = -(r+2*dr) > > ha, va = "right", "center" > > cstyle="angle,angleA=0,angleB=%f"%(theta,) > > print >> sys.stderr, ha, ",B,", va > > > > if foo: > > if theta - foo < 10: > > print >>sys.stderr, "Overlapping, offsetting a little > > bit" > > y1 = y1 + 0.1 > > foo = theta > > > > annotate(l1, > > (xc, yc), xycoords="data", > > xytext=(x1, y1), textcoords="data", ha=ha, va=va, > > arrowprops=dict(arrowstyle="-", > > connectionstyle=cstyle, > > patchB=p1)) > > > > - Rune > > > > 2010/3/23 Jae-Joon Lee <lee...@gm...> > >> > >> This should be doable using the annotation. Here is a simple cook-up I > >> just did. it uses a naive algorithm to place the labels, but I guess > >> it gives you an idea how things work. > >> a screenshot is attached. > >> > >> Regards, > >> > >> -JJ > >> > >> > >> from pylab import * > >> > >> # make a square figure and axes > >> figure(1, figsize=(6,6)) > >> ax = axes([0.1, 0.1, 0.8, 0.8]) > >> > >> labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' > >> fracs = [15,30,45, 10] > >> > >> explode=(0, 0.05, 0, 0) > >> p = pie(fracs, explode=explode, shadow=True) > >> title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5}) > >> > >> for p1, l1 in zip(p[0], labels): > >> r = p1.r > >> dr = r*0.1 > >> t1, t2 = p1.theta1, p1.theta2 > >> theta = (t1+t2)/2. > >> > >> xc, yc = r/2.*cos(theta/180.*pi), r/2.*sin(theta/180.*pi) > >> x1, y1 = (r+dr)*cos(theta/180.*pi), (r+dr)*sin(theta/180.*pi) > >> if x1 > 0 : > >> x1 = r+2*dr > >> ha, va = "left", "center" > >> tt = -180 > >> cstyle="angle,angleA=0,angleB=%f"%(theta,) > >> else: > >> x1 = -(r+2*dr) > >> ha, va = "right", "center" > >> tt = 0 > >> cstyle="angle,angleA=0,angleB=%f"%(theta,) > >> > >> annotate(l1, > >> (xc, yc), xycoords="data", > >> xytext=(x1, y1), textcoords="data", ha=ha, va=va, > >> arrowprops=dict(arrowstyle="-", > >> connectionstyle=cstyle, > >> patchB=p1)) > >> > >> show() > > > > > |
From: Chloe L. <ch...@be...> - 2010-03-28 08:53:58
|
Like so, not that it couldn't be improved: import matplotlib.cm as cm import matplotlib.colors as colors import pylab as p def rgb_to_dict(value, cbar): return dict(zip(('red','green','blue','alpha'), cbar(value))) def subcolorbar(xmin, xmax, cbar): '''Returns the part of cbar between xmin, xmax, scaled to 0,1.''' assert xmin < xmax assert xmax <=1 cd = cbar._segmentdata.copy() colornames = ('red','green','blue') rgbmin, rgbmax = rgb_to_dict(xmin, cbar), rgb_to_dict(xmax, cbar) for k in cd: tmp = [x for x in cd[k] if x[0] >= xmin and x[0] <= xmax] if tmp == [] or tmp[0][0] > xmin: tmp = [(xmin, rgbmin[k], rgbmin[k])] + tmp if tmp == [] or tmp[-1][0] < xmax: tmp = tmp + [ (xmax,rgbmax[k], rgbmax[k])] #now scale all this to (0,1) square = zip(*tmp) xbreaks = [(x - xmin)/(xmax-xmin) for x in square[0]] square[0] = xbreaks tmp = zip(*square) cd[k] = tmp return colors.LinearSegmentedColormap('local', cd, N=256) if __name__=="__main__": subset = [.1, .3, .6] scb = subcolorbar(min(subset), max(subset), cm.jet) print 'main segments', cm.jet._segmentdata print 'smaller', scb._segmentdata p.subplot(121) p.scatter([1,2,3],[1,2,3],s=49, c = subset, cmap=scb) p.colorbar() p.subplot(122) p.scatter([2,3,4],[2,3,4],s=49, c =[.001, .5, .99], cmap=cm.jet) p.colorbar() p.show() On Mar 27, 2010, at 11:52 PM, Chloe Lewis wrote: > To zoom in on the relevant section of a colorbar -- I convinced myself > once that I'd need an auxiliary function to define a new cdict that > covers only the current section of the original cdict. (and then > define a new colorbar from the cdict, and maybe do a little norming of > the data). > > _segmentdata will give you the original cdict for whichever colorbar > you're using. > > Not that I got around to actually doing it! But it would be great for > paper readability and passing-around of plots. > > &C > > > > On Mar 27, 2010, at 9:24 PM, Ariel Rokem wrote: > >> Hi Friedrich, >> >> Thanks a lot for your response. I think that you are right - using >> the vmin/vmax args into imshow (as well as into pcolor) does seem to >> do what I want. Great! >> >> The only thing that remains now is to simultaneously stretch the >> colormap in the image itself to this range, while also restricting >> the range of the colorbar which is displayed, to only the part of >> the colormap which actually has values (in the attached .png, I only >> want values between 0 and ~0.33 to appear in the colorbar, not from >> negative -0.33 to +0.33). >> >> Does anyone know how to do that? >> >> Thanks again - >> >> Ariel >> >> On Sat, Mar 27, 2010 at 3:29 PM, Friedrich Romstedt <fri...@gm... >>> wrote: >> 2010/3/27 Ariel Rokem <ar...@be...>: >>> I am trying to make a color-map which will respond to the range of >> values in >>> the data itself. That is - I want to take one of the mpl colormaps >> and use >>> parts of it, depending on the range of the data. >>> >>> In particular, I am interested in using the plt.cm.RdYlBu_r >> colormap. If the >>> data has both negative and positive values, I want 0 to map to the >> central >>> value of this colormap (a pale whitish yellow) and I want negative >> values to >>> be in blue and positive numbers to be in red. Also - I would want >> to use the >>> parts of the colormap that represent how far away the smallest and >> largest >>> values in the data are from 0. So - if my data is in the range >> [x1,x2] I >>> would want to use the part of the colormap in indices >>> 127-127*abs(x1)/(x2-x1) through 127+127*x2/(x2-x1). If the data only >>> includes positive numbers, I would want to only use the blue part >> of the >>> colormap and if there are negative numbers, I would want to only >> use the red >>> part of the colormap (in these cases, I would also want to take >> only a >>> portion of the colormap which represents the size of the interval >> [x1,x2] >>> relative to the interval [0,x1] or [x2,0], as the case may be). >>> >>> I think that this might be useful when comparing matrices >> generated from >>> different data, but with the same computation, such as correlation >> or >>> coherence (see http://nipy.sourceforge.net/nitime/examples/ >> fmri.html to get >>> an idea of what I mean). >> >> I might miss something important, but why not use pcolor() with >> kwargs >> vmin and vmax, >> http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.pcolor >> , >> e.g.: >> >> maxval = numpy.abs(C).max() >> pcolor(C, vmin = -maxval, vmax = maxval) >> >> As far as I can judge, this should have the desired effect. >> >> Friedrich >> >> >> >> -- >> Ariel Rokem >> Helen Wills Neuroscience Institute >> University of California, Berkeley >> http://argentum.ucbso.berkeley.edu/ariel >> < >> colorbar >> .png >>> >> ------------------------------------------------------------------------------ >> Download Intel® Parallel Studio Eval >> Try the new software tools for yourself. Speed compiling, find bugs >> proactively, and fine-tune applications for parallel performance. >> See why Intel Parallel Studio got high marks during beta. >> http://p.sf.net/sfu/intel-sw-dev_______________________________________________ >> Matplotlib-users mailing list >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Chloe L. <ch...@be...> - 2010-03-28 06:52:41
|
To zoom in on the relevant section of a colorbar -- I convinced myself once that I'd need an auxiliary function to define a new cdict that covers only the current section of the original cdict. (and then define a new colorbar from the cdict, and maybe do a little norming of the data). _segmentdata will give you the original cdict for whichever colorbar you're using. Not that I got around to actually doing it! But it would be great for paper readability and passing-around of plots. &C On Mar 27, 2010, at 9:24 PM, Ariel Rokem wrote: > Hi Friedrich, > > Thanks a lot for your response. I think that you are right - using > the vmin/vmax args into imshow (as well as into pcolor) does seem to > do what I want. Great! > > The only thing that remains now is to simultaneously stretch the > colormap in the image itself to this range, while also restricting > the range of the colorbar which is displayed, to only the part of > the colormap which actually has values (in the attached .png, I only > want values between 0 and ~0.33 to appear in the colorbar, not from > negative -0.33 to +0.33). > > Does anyone know how to do that? > > Thanks again - > > Ariel > > On Sat, Mar 27, 2010 at 3:29 PM, Friedrich Romstedt <fri...@gm... > > wrote: > 2010/3/27 Ariel Rokem <ar...@be...>: > > I am trying to make a color-map which will respond to the range of > values in > > the data itself. That is - I want to take one of the mpl colormaps > and use > > parts of it, depending on the range of the data. > > > > In particular, I am interested in using the plt.cm.RdYlBu_r > colormap. If the > > data has both negative and positive values, I want 0 to map to the > central > > value of this colormap (a pale whitish yellow) and I want negative > values to > > be in blue and positive numbers to be in red. Also - I would want > to use the > > parts of the colormap that represent how far away the smallest and > largest > > values in the data are from 0. So - if my data is in the range > [x1,x2] I > > would want to use the part of the colormap in indices > > 127-127*abs(x1)/(x2-x1) through 127+127*x2/(x2-x1). If the data only > > includes positive numbers, I would want to only use the blue part > of the > > colormap and if there are negative numbers, I would want to only > use the red > > part of the colormap (in these cases, I would also want to take > only a > > portion of the colormap which represents the size of the interval > [x1,x2] > > relative to the interval [0,x1] or [x2,0], as the case may be). > > > > I think that this might be useful when comparing matrices > generated from > > different data, but with the same computation, such as correlation > or > > coherence (see http://nipy.sourceforge.net/nitime/examples/ > fmri.html to get > > an idea of what I mean). > > I might miss something important, but why not use pcolor() with kwargs > vmin and vmax, > http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.pcolor > , > e.g.: > > maxval = numpy.abs(C).max() > pcolor(C, vmin = -maxval, vmax = maxval) > > As far as I can judge, this should have the desired effect. > > Friedrich > > > > -- > Ariel Rokem > Helen Wills Neuroscience Institute > University of California, Berkeley > http://argentum.ucbso.berkeley.edu/ariel > < > colorbar > .png > > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev_______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Filipe P. A. F. <oc...@gm...> - 2010-03-28 03:55:00
|
Hello list I've trying for a while a "python only" solution to remove white spaces that Basemap generate to keep the aspect ratio. I found these two threads that explain the issue better: http://www.mail-archive.com/mat...@li.../msg14430.html http://www.mail-archive.com/mat...@li.../msg14262.html In the past I relied on ImageMagick's "convert" command with the "-trim white" option for the job. However, just recently I came across with this other list and a PIL solution: http://mail.python.org/pipermail/image-sig/2008-July/005092.html Here is how I'm doing: savefig('mapa.png', dpi=300) from PIL import Image im = Image.open("mapa.png") def trim(im, border): from PIL import ImageChops bg = Image.new(im.mode, im.size, border) diff = ImageChops.difference(im, bg) bbox = diff.getbbox() if bbox: return im.crop(bbox) else: # found no content raise ValueError("cannot trim; image was empty") im2=trim(im,'white') im2.show() This works and the aspect ratio is preserved, but as you can see, it is not a very smart implementation. I save and then reload it again... any suggestions to improve this are welcome. Also, I have not tried this on figures with labels and annotations. Thanks for any input. ***************************************************** Filipe Pires Alvarenga Fernandes University of Massachusetts Dartmouth 200 Mill Road - Fairhaven, MA Tel: (508) 910-6381 Email: fal...@um... oc...@ya... oc...@gm... http://ocefpaf.tiddlyspot.com/ ***************************************************** |