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) |
|
|
|
I once had a similar issue. I solved it like this. It takes the minimum and maximum of the data and returns a colormap: Zero: White, Positive values: blue, Negative values: red. def mxcmap(_min,_max): if _min >= 0 and _max >= 0: cdict = {'red': ((0.0, 1.0, 1.0), (1.0, 0.0, 0.0)), 'green': ((0.0, 1.0, 1.0), (1.0, 0.0, 0.0)), 'blue': ((0.0, 1.0, 1.0), (1.0, 1.0, 1.0))} elif _min <= 0 and _max <= 0: cdict = {'red': ((0.0, 1.0, 1.0), (1.0, 1.0, 1.0)), 'green': ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)), 'blue': ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0))} else: full_red = 1 full_blue = 1 if -_min > _max: full_blue = -float(_max)/_min else: full_red = -float(_min)/_max zero = 0.5-((_max+_min)/2.)/(_max-_min) cdict = {'red': ((0.0, 1.0, 1.0), (zero, 1.0, 1.0), (1.0, 1-full_blue, 1-full_blue)), 'green': ((0.0, 1-full_red, 1-full_red), (zero, 1.0, 1.0), (1.0, 1-full_blue, 1-full_blue)), 'blue': ((0.0, 1-full_red, 1-full_red), (zero,1.0, 1.0), (1.0, 1.0, 1.0))} return pylab.matplotlib.colors.LinearSegmentedColormap('my_colormap',cdict,256) -- View this message in context: http://old.nabble.com/Making-a-data-driven-colormap-tp28050311p28067995.html Sent from the matplotlib - users mailing list archive at Nabble.com.
Hi, is it possible to perform a surface plot a NxM matrix with date-axes? Similar to plot_date for 1D-Plots. The dates are available as an N-sized (or M-sized) array of float values. At the moment, I am using imshow or matshow for the color plots, but the only way I found to manipulate the axes is the 'extent' keyword argument, which is not sufficient in this context. Any hints? Micha -- View this message in context: http://old.nabble.com/matshow---imshow-with-date-axis-tp28068228p28068228.html Sent from the matplotlib - users mailing list archive at Nabble.com.
2010年3月29日 Alan G Isaac <ala...@gm...>: > Can you explain this: > norm = colors.Normalize(vmin = -1, vmax = 1) The normaliser takes some arbitrary value and returns a value in [0, 1]. Hence the name. The value \in [0, 1] is handed over to the cmap's __call__(), resulting in the color value. And yes, I guess you can use vmin and vmax directly, it's just a matter of taste. As you can pass in also *boundaries* to Colorbar(), this may be an alternative. It will display all red above the max value, though it's harder to tick. When you want the highest value to be really represented by red, not near-to-red. Friedrich
I noticed that colorbar.Colorbar treats segmentation via *boundaries* as compulsory, i.e., it thinks it must tick at the *boundaries* or nowhere. Wouldn't it be useful to have an kwarg which overrides this and always uses ticker.MaxNLocator()? Friedrich
matplotlib.ticker:748: # ORIGINAL: # step = max(int(0.99 + len(self.locs) / float(self.nbins)), 1) step = int(math.ceil(len(self.locs) / (self.nbins + 1))) There is a from __future__ import division statement. Who verifies (or falsifies)? I checked with values len(locs) = 10, 11, 12, 100, 101, 110, 111, and nbins = 10, and it works (it didn't before) for me. I have a proof available. Friedrich
On 3/28/2010 7:19 PM, Friedrich Romstedt wrote: > I fixed your problem Can you explain this: norm = colors.Normalize(vmin = -1, vmax = 1) I take it that this scales the range for the color bar, which is what 'luminance' must refer to in the docs? In which case, can we just set vmin and vmax as imshow keywords? patch = ax.imshow(Z, interpolation='nearest', extent=[-5,5,-5,5], vmin = -1, vmax = 1) (Seems to work.) Thanks! Alan
Yeates, Mathew C (388D) wrote: > Hi > > I would expect > > hgt=ma.masked_where(div == 0,hgt) > > m.contourf(x,y,hgt,15,cmap=plt.cm.jet) > > > > to produce a map complementary to the map produced by > > > > hgt=ma.masked_where(div != 0,hgt) > > m.contourf(x,y,hgt,15,cmap=plt.cm.jet) > > > > But, this is not the case. > > What am I missing? Basemap contourf calls mpl contourf, and mpl contourf leaves a grid box empty if any of its corners is masked. Does this account for what you are seeing? Eric
2010年3月28日 Chloe Lewis <ch...@be...>: > 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. It seems that I cannot read the sections following after the "From this:" and "I get this:"? But anyway, I solved it for you :-) See attached script. colorbar() takes the argument *boundaries*, defining the region to draw. It's code from Alan G Isaac slightly modified and also posted there back, too. You will want to run the code via python -i norm.py. For the vmin and vmax, if you like it more you can also pass in norm = matplotlib.colors.Normalize(vmin, vmax) instead. Note that the ticking is a bit weird, there is also a bug in matplotlib I will report on right after this e-mail, whose bugfix you will maybe want to apply to get ticking properly working. When you have insane values for C.min() and C.max() anyway, I'm afraid you have to retick manually with *ticks* to colorbar(). The ticker.MaxNLocator is only used when not using the *boundaries* arg to colorbar(), unfortunately. Otherwise it tries to create maximal many and less than 11 ticks by using the lowest value and an appropriate step in *boundaries*. I think the implementation of ticking is cumbersome and never optimal. Friedrich
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.
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
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
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:
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
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
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
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
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)
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
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..
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() > > > > >
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
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
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/ *****************************************************
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
Hi Brian, Thanks for the code - this is definitely in the direction of what I want to make! The RdYlBu_r colormap is one of the built-in colormaps available in matplotlib.pyplot.cm (you can see all of them here: http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps). I think that using the built-in colormaps might give nicer transitions between the colors, so instead of transitioning linearily between red and white and white and blue, it transitions in a slightly non-linear way, along several segments. Compare: plot(plt.cm.RdYlBu_r(arange(256))) with plot(my_cmap(arange(256))) I think that the more nonlinear one might look a little bit nicer (and might be less perceptually misleading in interpreting color differences in the result). But I need to figure out how many segments there are in there. Thanks - Ariel On Sat, Mar 27, 2010 at 4:14 AM, Brian Blais <bb...@br...> wrote: > On Mar 27, 2010, at 1:13 , Ariel Rokem wrote: > > 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. > > > not sure if this is what you want (I'd never heard of RdYlBu_r...I need to > go read up!), but I've used a similar colormap with the code posted below. > You might be able to modify it for your case. > > > hope this helps! > > bb > > from pylab import * > > def bluewhitered(a,N=256): > bottom = [0, 0, 0.5] > botmiddle = [0, 0.5, 1] > middle = [1, 1, 1] > topmiddle = [1, 0, 0] > top = [0.5, 0, 0] > > lims=[a.min(),a.max()] > > if lims[0]<0 and lims[1]>0: > ratio=abs(lims[0])/(abs(lims[0])+lims[1]) > > cdict={} > cdict['red']=[] > cdict['green']=[] > cdict['blue']=[] > > # negative part > red=[(0.0, 0.0, 0.0), > (ratio/2, 0.0, 0.0), > (ratio, 1.0, 1.0)] > green=[(0.0, 0.0, 0.0), > (ratio/2, 0.5, 0.5), > (ratio, 1.0, 1.0)] > blue=[(0.0, 0.5, 0.5), > (ratio/2, 1, 1), > (ratio, 1.0, 1.0)] > > cdict['red'].extend(red) > cdict['green'].extend(green) > cdict['blue'].extend(blue) > > nratio=1-(1-ratio)/2.0 > # positive part > red=[(ratio, 1.0, 1.0), > (nratio, 1.0, 1.0), > (1, 0.5, 0.5)] > green=[(ratio, 1.0, 1.0), > (nratio, 0., 0.), > (1, 0.0, 0.0)] > blue=[(ratio, 1., 1.), > (nratio, 0, 0), > (1, 0, 0)] > > cdict['red'].extend(red) > cdict['green'].extend(green) > cdict['blue'].extend(blue) > > > > > elif lims[0]>=0: # all positive > cdict={} > cdict['red']=[] > cdict['green']=[] > cdict['blue']=[] > > ratio=0.0 > nratio=0.5 > > # positive part > red=[(ratio, 1.0, 1.0), > (nratio, 1.0, 1.0), > (1, 0.5, 0.5)] > green=[(ratio, 1.0, 1.0), > (nratio, 0., 0.), > (1, 0.0, 0.0)] > blue=[(ratio, 1., 1.), > (nratio, 0, 0), > (1, 0, 0)] > > cdict['red'].extend(red) > cdict['green'].extend(green) > cdict['blue'].extend(blue) > > else: # all negative > cdict={} > cdict['red']=[] > cdict['green']=[] > cdict['blue']=[] > > ratio=1.0 > > # negative part > red=[(0.0, 0.0, 0.0), > (ratio/2, 0.0, 0.0), > (ratio, 1.0, 1.0)] > green=[(0.0, 0.0, 0.0), > (ratio/2, 0.5, 0.5), > (ratio, 1.0, 1.0)] > blue=[(0.0, 0.5, 0.5), > (ratio/2, 1, 1), > (ratio, 1.0, 1.0)] > > cdict['red'].extend(red) > cdict['green'].extend(green) > cdict['blue'].extend(blue) > > my_cmap = > matplotlib.colors.LinearSegmentedColormap('my_colormap',cdict,N) > > > return my_cmap > > if __name__=="__main__": > > a=randn(20,20) > my_cmap=bluewhitered(a,256) > > > > clf() > pcolor(a,cmap=my_cmap) > colorbar() > > > > > > > > -- > Brian Blais > bb...@br... > http://web.bryant.edu/~bblais <http://web.bryant.edu/%7Ebblais> > http://bblais.blogspot.com/ > > > > -- Ariel Rokem Helen Wills Neuroscience Institute University of California, Berkeley http://argentum.ucbso.berkeley.edu/ariel