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




Showing results of 394

<< < 1 .. 8 9 10 11 12 .. 16 > >> (Page 10 of 16)
From: Eric F. <ef...@ha...> - 2009年03月16日 00:32:45
Pablo Romero wrote:
> This is related to a previous question I had about colormaps;
> Im looking for a method to evenly split up a colormap into an RGB colors array.
> something like:
> 
> def cmap_to_array(cmap,N):
> ...
> 
> mycolors=cmap_to_array(cm.jet,20)
> lev=np.arange(1,20,1)
> cs=contourf(Z,lev,colors=mycolors)
> 
> ...
> 
> where 'mycolors' would be a 20x3 array with RGB values for 20 colors that represent the cm.jet spectrum broken up evenly into 20 colors...
> 
> I believe colors array can contain RGB tuples, something like [[0.2,0.3,1],[0.3,0.5,1], ... ,[1,1,0]] should work.
> 
> However, I dont know how to extract the tuples from an existing colormap.
> How can this be done?
Pablo,
I think that what you want can be handled very simply using the 
BoundaryNorm as I have suggested earlier. However, it is not hard to 
generate any number of evenly spaced colors (for use in the "colors" 
kwarg of contourf). Here is one way to do it:
import numpy as np
import matplotlib.cm as cm
def make_N_colors(cmap_name, N):
 cmap = cm.get_cmap(cmap_name, N)
 return cmap(np.arange(N))
This will return a sequence of RGBA values, actually an Nx4 ndarray. I 
don't think the inclusion of the 4th column hurts anything, but 
obviously you can use indexing to remove it if you want to. The last 
line in the function would change to
 return cmap(np.arange(N))[:,:-1]
cmap_name is a string chosen from the values in cm.datad.keys().
You will want N to be len(lev) - 1.
Eric
From: Pablo R. <rom...@ho...> - 2009年03月16日 00:21:44
Please disregard this question, as a solution was found to this problem using the 'BoundaryNorm' function.
 
P.Romero
----------------------------------------
> From: rom...@ho...
> To: mat...@li...
> Date: 2009年3月15日 13:37:04 -0700
> Subject: [Matplotlib-users] convert colormap to RGB color array
>
>
> This is related to a previous question I had about colormaps;
> Im looking for a method to evenly split up a colormap into an RGB colors array.
> something like:
>
> def cmap_to_array(cmap,N):
> ...
>
> mycolors=cmap_to_array(cm.jet,20)
> lev=np.arange(1,20,1)
> cs=contourf(Z,lev,colors=mycolors)
>
> ...
>
> where 'mycolors' would be a 20x3 array with RGB values for 20 colors that represent the cm.jet spectrum broken up evenly into 20 colors...
>
> I believe colors array can contain RGB tuples, something like [[0.2,0.3,1],[0.3,0.5,1], ... ,[1,1,0]] should work.
>
> However, I dont know how to extract the tuples from an existing colormap.
> How can this be done?
>
>
> Please help...
> Thanks,
>
> P.Romero
> _________________________________________________________________
> Windows LiveTM Groups: Create an online spot for your favorite groups to meet.
> http://windowslive.com/online/groups?ocid=TXT_TAGLM_WL_groups_032009
> ------------------------------------------------------------------------------
> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
> software that enables intelligent coding and step-through debugging.
> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
_________________________________________________________________
Windows LiveTM Contacts: Organize your contact list. 
http://windowslive.com/connect/post/marcusatmicrosoft.spaces.live.com-Blog-cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009
From: Pablo R. <rom...@ho...> - 2009年03月16日 00:21:01
Eric,
the "BoundaryNorm" was what I was looking for.
it did exactly what I needed; split the colormap up evenly into discrete colors based on the number of elements in my levels array.
 
Thanks,
P.Romero
----------------------------------------
> Date: 2009年3月15日 10:38:22 -1000
> From: ef...@ha...
> Subject: Re: [Matplotlib-users] question about levels & colormaps for contour functions
> To: rom...@ho...; mat...@li...
>
> Pablo Romero wrote:
>> Eric,
>>
>> I believe the problem is that my 19 levels are not evenly distributed;
>>
>> Lv=(1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)
>
> No, I don't think that has much to do with it, unless the problem is
> that the colors of some levels are too similar.
>
> Again, please make a simple, complete, self-contained example, and we
> will go from there.
>
> I think what you want may be something like this:
>
> levs=[1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75]
> norm = mpl.colors.BoundaryNorm(levs, 256)
> z = rand(10,15)*14 # fake data covering only lower levs
> contourf(z, levs, norm=norm, cmap=cm.jet, extend='both')
> colorbar()
>
>
>>
>> the first part of the range starts at 1,3,5, but then includes 6,7,8,9, and then only goes with even numbers..10,12,14,16,18,20...then by 5 up until 35, then jumps by 10...etc.
>>
>> I know this seems strange, but this was done because Im plotting 'ocean wave heights' and these were decided to be the 'heights of interest' for the project Im working on.
>>
>
> Perfectly reasonable.
>
>> anyway, what I want is to be able to breakup the 'cm.jet' spectrum evenly based on the # of levels (and not on their values), and spread my levels evenly across the spectrum....
>>
>> i.e., I want the first 6-7 levels to be evenly spread from blue to about green acros cm.jet's spectrum, approx. the next 6 levels to be evenly spread across cm.jet's yellow-orange part of the spectrum, and the last few levels to be evenly spread across the reds...
>>
>> Ideally, Id like to be able to use any colormap, and simply break up its color spectrum evenly, and then assign each distinct color to each level in my levels array.
>>
>> So, I guess I need a method to programatically, evenly break up cm.jet by the # of levels, create a colors array & pass this array to contourf(colors='mycolorsarray')...
>>
>> does this make sense?
>>
>> P.Romero
>>
>> ----------------------------------------
>>> Date: 2009年3月15日 08:32:32 -1000
>>> From: ef...@ha...
>>> Subject: Re: [Matplotlib-users] question about levels & colormaps for contour functions
>>> To: rom...@ho...
>>> CC: mat...@li...
>>>
>>> Pablo Romero wrote:
>>>> Hi,
>>>>
>>>> I would like to know how I can pass an array of levels and also a colormap to the contour() function and have the levels span the entire colormap. example...
>>>>
>>>> if I do the following....
>>>>
>>>>
>>>> Lv=(1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)
>>>>
>>>> cs=plt.contourf(X,Y,waveheight,Lv,cmap=cm.jet,extend='both')
>>>>
>>>>
>>>> I would expect that contours that are in the higher levels (i.e., levels above value '14' in my levels array) would be plotted with lighter colors in the cm.jet spectrum; the greens, yellows,oranges,reds, etc.
>>>>
>>>> However, contourf is simply breaking up the lower,"dark blue" half of the cm.jet spectrum into small slices, and spreading all of my levels throughout only the bottom half of cm.jet.
>>>>
>>> I don't see the problem yet. Here is an attempt to recreate what it
>>> sounds like you are describing above (run in ipython -pylab):
>>>
>>> contourf(rand(10,12), arange(0,5.01,0.2), cmap=cm.jet, extend='both')
>>> colorbar()
>>>
>>> The data are all blue because they are in the 0-1 range, while the
>>> levels span the 0-5 range. The colorbar shows that the colormap is
>>> covering the latter range, as it should.
>>>
>>> If you can make a simple self-contained example like this, and then
>>> describe the difference between what it does and what you want it to do,
>>> we can figure out how to get your desired result.
>>>
>>> Eric
>>>
>>>
>>>
>>>
>>>
>>>> I followed this tutorial:
>>>> http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations
>>>>
>>>> that shows how to create a "discrete" colormap, but this also didnt work; the contourf function again simply sliced up the lower, blue colors and spread my all of my layers across the "blues" in my discrete colormap.
>>>>
>>>>
>>>> If I use a colors array instead of a colormap, I can achieve what I want. However, Id like to be able to use a colormap so that I dont have to manually create color arrays everytime that I want to change my colorscheme.
>>>>
>>>> So, how can I force contour() to spread my levels across THE WHOLE spectrum of a colormap?
>>>>
>>>> Please help,
>>>>
>>>> Thanks,
>>>> P.Romero
>>>>
>>>>
>>>> _________________________________________________________________
>>>> Express your personality in color! Preview and select themes for Hotmail®.
>>>> http://www.windowslive-hotmail.com/LearnMore/personalize.aspx?ocid=TXT_MSGTX_WL_HM_express_032009#colortheme
>>>> ------------------------------------------------------------------------------
>>>> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
>>>> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
>>>> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
>>>> software that enables intelligent coding and step-through debugging.
>>>> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
>>>> _______________________________________________
>>>> Matplotlib-users mailing list
>>>> Mat...@li...
>>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>> _________________________________________________________________
>> Windows LiveTM Contacts: Organize your contact list.
>> http://windowslive.com/connect/post/marcusatmicrosoft.spaces.live.com-Blog-cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009
>
_________________________________________________________________
Windows LiveTM Contacts: Organize your contact list. 
http://windowslive.com/connect/post/marcusatmicrosoft.spaces.live.com-Blog-cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009
From: Eric F. <ef...@ha...> - 2009年03月15日 20:39:08
Pablo Romero wrote:
> Eric,
> 
> I believe the problem is that my 19 levels are not evenly distributed; 
> 
> Lv=(1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)
No, I don't think that has much to do with it, unless the problem is 
that the colors of some levels are too similar.
Again, please make a simple, complete, self-contained example, and we 
will go from there.
I think what you want may be something like this:
levs=[1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75]
norm = mpl.colors.BoundaryNorm(levs, 256)
z = rand(10,15)*14 # fake data covering only lower levs
contourf(z, levs, norm=norm, cmap=cm.jet, extend='both')
colorbar()
> 
> the first part of the range starts at 1,3,5, but then includes 6,7,8,9, and then only goes with even numbers..10,12,14,16,18,20...then by 5 up until 35, then jumps by 10...etc.
> 
> I know this seems strange, but this was done because Im plotting 'ocean wave heights' and these were decided to be the 'heights of interest' for the project Im working on.
> 
Perfectly reasonable.
> anyway, what I want is to be able to breakup the 'cm.jet' spectrum evenly based on the # of levels (and not on their values), and spread my levels evenly across the spectrum....
> 
> i.e., I want the first 6-7 levels to be evenly spread from blue to about green acros cm.jet's spectrum, approx. the next 6 levels to be evenly spread across cm.jet's yellow-orange part of the spectrum, and the last few levels to be evenly spread across the reds...
> 
> Ideally, Id like to be able to use any colormap, and simply break up its color spectrum evenly, and then assign each distinct color to each level in my levels array. 
> 
> So, I guess I need a method to programatically, evenly break up cm.jet by the # of levels, create a colors array & pass this array to contourf(colors='mycolorsarray')...
> 
> does this make sense?
> 
> P.Romero
> 
> ----------------------------------------
>> Date: 2009年3月15日 08:32:32 -1000
>> From: ef...@ha...
>> Subject: Re: [Matplotlib-users] question about levels & colormaps for contour functions
>> To: rom...@ho...
>> CC: mat...@li...
>>
>> Pablo Romero wrote:
>>> Hi,
>>>
>>> I would like to know how I can pass an array of levels and also a colormap to the contour() function and have the levels span the entire colormap. example...
>>>
>>> if I do the following....
>>>
>>>
>>> Lv=(1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)
>>>
>>> cs=plt.contourf(X,Y,waveheight,Lv,cmap=cm.jet,extend='both')
>>>
>>>
>>> I would expect that contours that are in the higher levels (i.e., levels above value '14' in my levels array) would be plotted with lighter colors in the cm.jet spectrum; the greens, yellows,oranges,reds, etc.
>>>
>>> However, contourf is simply breaking up the lower,"dark blue" half of the cm.jet spectrum into small slices, and spreading all of my levels throughout only the bottom half of cm.jet.
>>>
>> I don't see the problem yet. Here is an attempt to recreate what it
>> sounds like you are describing above (run in ipython -pylab):
>>
>> contourf(rand(10,12), arange(0,5.01,0.2), cmap=cm.jet, extend='both')
>> colorbar()
>>
>> The data are all blue because they are in the 0-1 range, while the
>> levels span the 0-5 range. The colorbar shows that the colormap is
>> covering the latter range, as it should.
>>
>> If you can make a simple self-contained example like this, and then
>> describe the difference between what it does and what you want it to do,
>> we can figure out how to get your desired result.
>>
>> Eric
>>
>>
>>
>>
>>
>>> I followed this tutorial:
>>> http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations
>>>
>>> that shows how to create a "discrete" colormap, but this also didnt work; the contourf function again simply sliced up the lower, blue colors and spread my all of my layers across the "blues" in my discrete colormap.
>>>
>>>
>>> If I use a colors array instead of a colormap, I can achieve what I want. However, Id like to be able to use a colormap so that I dont have to manually create color arrays everytime that I want to change my colorscheme.
>>>
>>> So, how can I force contour() to spread my levels across THE WHOLE spectrum of a colormap?
>>>
>>> Please help,
>>>
>>> Thanks,
>>> P.Romero
>>>
>>>
>>> _________________________________________________________________
>>> Express your personality in color! Preview and select themes for Hotmail®.
>>> http://www.windowslive-hotmail.com/LearnMore/personalize.aspx?ocid=TXT_MSGTX_WL_HM_express_032009#colortheme
>>> ------------------------------------------------------------------------------
>>> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
>>> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
>>> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
>>> software that enables intelligent coding and step-through debugging.
>>> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
>>> _______________________________________________
>>> Matplotlib-users mailing list
>>> Mat...@li...
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> _________________________________________________________________
> Windows LiveTM Contacts: Organize your contact list. 
> http://windowslive.com/connect/post/marcusatmicrosoft.spaces.live.com-Blog-cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009
From: Pablo R. <rom...@ho...> - 2009年03月15日 20:37:53
This is related to a previous question I had about colormaps;
Im looking for a method to evenly split up a colormap into an RGB colors array.
something like:
 
def cmap_to_array(cmap,N):
...
 
mycolors=cmap_to_array(cm.jet,20)
lev=np.arange(1,20,1)
cs=contourf(Z,lev,colors=mycolors)
 
...
where 'mycolors' would be a 20x3 array with RGB values for 20 colors that represent the cm.jet spectrum broken up evenly into 20 colors...
 
I believe colors array can contain RGB tuples, something like [[0.2,0.3,1],[0.3,0.5,1], ... ,[1,1,0]] should work.
However, I dont know how to extract the tuples from an existing colormap.
How can this be done?
 
 
Please help...
Thanks,
 
P.Romero
_________________________________________________________________
Windows LiveTM Groups: Create an online spot for your favorite groups to meet.
http://windowslive.com/online/groups?ocid=TXT_TAGLM_WL_groups_032009
From: Eric F. <ef...@ha...> - 2009年03月15日 18:33:21
Pablo Romero wrote:
> Hi,
> 
> I would like to know how I can pass an array of levels and also a colormap to the contour() function and have the levels span the entire colormap. example...
> 
> if I do the following....
> 
> 
> Lv=(1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)
> 
> cs=plt.contourf(X,Y,waveheight,Lv,cmap=cm.jet,extend='both')
> 
> 
> I would expect that contours that are in the higher levels (i.e., levels above value '14' in my levels array) would be plotted with lighter colors in the cm.jet spectrum; the greens, yellows,oranges,reds, etc. 
> 
> However, contourf is simply breaking up the lower,"dark blue" half of the cm.jet spectrum into small slices, and spreading all of my levels throughout only the bottom half of cm.jet.
> 
I don't see the problem yet. Here is an attempt to recreate what it 
sounds like you are describing above (run in ipython -pylab):
contourf(rand(10,12), arange(0,5.01,0.2), cmap=cm.jet, extend='both')
colorbar()
The data are all blue because they are in the 0-1 range, while the 
levels span the 0-5 range. The colorbar shows that the colormap is 
covering the latter range, as it should.
If you can make a simple self-contained example like this, and then 
describe the difference between what it does and what you want it to do, 
we can figure out how to get your desired result.
Eric
> 
> I followed this tutorial:
> http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations
> 
> that shows how to create a "discrete" colormap, but this also didnt work; the contourf function again simply sliced up the lower, blue colors and spread my all of my layers across the "blues" in my discrete colormap.
> 
> 
> If I use a colors array instead of a colormap, I can achieve what I want. However, Id like to be able to use a colormap so that I dont have to manually create color arrays everytime that I want to change my colorscheme.
> 
> So, how can I force contour() to spread my levels across THE WHOLE spectrum of a colormap?
> 
> Please help,
> 
> Thanks,
> P.Romero
> 
> 
> _________________________________________________________________
> Express your personality in color! Preview and select themes for Hotmail®. 
> http://www.windowslive-hotmail.com/LearnMore/personalize.aspx?ocid=TXT_MSGTX_WL_HM_express_032009#colortheme
> ------------------------------------------------------------------------------
> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
> software that enables intelligent coding and step-through debugging.
> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Pablo R. <rom...@ho...> - 2009年03月15日 17:00:14
Hi,
 
I would like to know how I can pass an array of levels and also a colormap to the contour() function and have the levels span the entire colormap. example...
 
if I do the following....
 
Lv=(1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)
 
cs=plt.contourf(X,Y,waveheight,Lv,cmap=cm.jet,extend='both')
 
 
I would expect that contours that are in the higher levels (i.e., levels above value '14' in my levels array) would be plotted with lighter colors in the cm.jet spectrum; the greens, yellows,oranges,reds, etc. 
 
However, contourf is simply breaking up the lower,"dark blue" half of the cm.jet spectrum into small slices, and spreading all of my levels throughout only the bottom half of cm.jet.
 
 
I followed this tutorial:
http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations
 
that shows how to create a "discrete" colormap, but this also didnt work; the contourf function again simply sliced up the lower, blue colors and spread my all of my layers across the "blues" in my discrete colormap.
 
 
If I use a colors array instead of a colormap, I can achieve what I want. However, Id like to be able to use a colormap so that I dont have to manually create color arrays everytime that I want to change my colorscheme.
 
So, how can I force contour() to spread my levels across THE WHOLE spectrum of a colormap?
 
Please help,
 
Thanks,
P.Romero
 
 
_________________________________________________________________
Express your personality in color! Preview and select themes for Hotmail®. 
http://www.windowslive-hotmail.com/LearnMore/personalize.aspx?ocid=TXT_MSGTX_WL_HM_express_032009#colortheme
From: Pablo R. <rom...@ho...> - 2009年03月15日 04:51:03
Eric,
version matplotlib-0.98.5.2
running on fedora 9, i386.
 
the pause was significant, up to about 30 seconds to a minute.
 
HOWEVER, your delete_masked_points() solution worked incredibly, reducing the amount of vertices by a giant amount (in one case, from 6,000+ to 180 vertices), and the rendering time to almost nothing.
 
Im still not clear on how the 'delete_masked_points()' or 'X.ravel()' functions work; I need to read up on these.
 
One thing that *IS* clear is that my previous X,Y arrays were 2D arrays, and the resulting x,y arrays after using your solution are only 1D arrays. The new 1D X,Y arrays do work with the quiver() function, which I dont understand, since I was under the impression that these X,Y arrays needed to be created using a method like this:
 
m=basemap(...)
X,Y=m(*numpy.meshgrid(lat_points_array,lon_points_array))
 
and that this should, in theory, create the 2D X,Y arrays that quiver requires, correct?
 
am I missing something here?
 
 
the new 1D arrays are more than twice the size than the original arrays as reported by 'len()', but they are obviously much smaller due to the fact that they are 1D arrays.
 
Anyway, thanks again for the help,
P.Romero
----------------------------------------
> Date: 2009年3月14日 17:57:27 -1000
> From: ef...@ha...
> Subject: Re: [Matplotlib-users] problem with (poor) quiver performance & X, Y, U, V arrays
> To: rom...@ho...
> CC: mat...@li...
>
> Pablo Romero wrote:
>> Im experiencing very poor performance when using the 'quiver' function over relatively large grids.
>> Im using quiver to plot wind 'u,v' data over a lat/lon grid using basemap.
>>
>> quiver performs decently over small lat/lon ranges, such as a bounding box of lat(0-30),lon(-120- -100), but when I try to plot larger areas (i.e. the entire globe), quiver causes a very large pause. through some debugging of quiver.py, I narrowed down the performance lag to the "set_vertices" function call within the "draw()" function in the quiver class. as a test, I printed 'len(vert)' in order to see the vertice array length that was causing problems...it seems that Im getting vertice counts in the high thousands, and quiver seems to struggle with this.
>>
>> should quiver be able to easily handle such a large amount of vertices?
>
> What version of matplotlib are you using, and on what platform?
>
> How long is the pause, and for how many vectors?
>
> I presume you are referring to the set_verts() method which is inherited
> from collections.PolyCollection. It is using a list comprehension to
> loop over the vectors, making a path for each, so I would not expect it
> to be particularly quick; but whether it is unreasonable, or whether it
> can be sped up reasonably easily, I don't know.
>
>>
>>
>> A secondary question:
>> the method Im using to create my X,Y,U,V arrays is creating 'larger-than-necessary' X,Y arrays; i.e., Im not plotting the U,V vectors at each lat&lon point, Im 'skipping' over 'every-nth-point', so my U,V arrays are equal in size to my X,Y arrays, but have many empty elements.
>>
>> Unfortunately, the array data is being imported from an external program (named 'GRADS'), so I cannot prevent these arrays from being 'oversized' upon their creation.
>>
>> example:
>> for a (10 degree lat)x(10 degree lon) area, I might have arrays like this:
>>
>> X='[0,0.5,1.0,1.5,2.0,2.5,...10.0],[0,0.5,...10],...[0.0,0.5,...10.0]'
>> Y='[0,0.5,1.0,1.5,2.0,2.5,...10.0],[0,0.5,...10],...[0.0,0.5,...10.0]'
>> U='[--,--,0.40,--,--,0.15,...0.30],[--,--,0.25,--,--...,0.12],...[--,--,0.50,...10.0]'
>> V='[--,--,0.30,--,--,0.25,...0.40],[--,--,0.25,--,--...,0.12],...[--,--,0.50,...10.0]'
>>
>> these values are completely inaccurate and are meant just to illustrate the fact that I have many 'skipped' values in my U,V arrays, and I have oversized X,Y arrays that cover the 10x10 lat/lon grid...
>>
>> So, what I want to do is create NEW X,Y,U,V arrays or remove elements from these existing X,Y,U,V arrays, so that:
>> 1) only valid, "non-empty" values will exist in my U,V arrays..and
>> 2) the only values that exist in X,Y are those that correspond to valid points in the U,V arrays...
>>
>> Im not very experienced with python/matplotlib, so I dont know what would be the best way to iterate over these 4 arrays and remove the empty invalid elements (or copy the valid elements into new arrays). How can I go about shortening these arrays?
>>
>
> Assuming your X, Y, U, V are all masked arrays or ndarrays of the same
> shape, you can use
>
> from matplotlib.cbook import delete_masked_points
>
> x,y,u,v = delete_masked_points(X.ravel(), Y.ravel(). U.ravel(), V.ravel())
>
> The Barbs class in quiver.py uses this function; Quiver could be
> modified to use it, with the loss of a bit of functionality that I
> suspect no one is using anyway.
>
> All the .ravel() method calls are needed only if the arrays are 2-D or
> higher.
>
>
>> Im hoping that with less points in my X,Y arrays, that quiver will perform faster since it isnt wasting time trying to process X,Y points where U,V are empty).
>>
>
> Let us know how much difference it makes, and tell us what the initial
> and modified number of vectors is.
>
> Eric
_________________________________________________________________
Windows LiveTM Groups: Create an online spot for your favorite groups to meet.
http://windowslive.com/online/groups?ocid=TXT_TAGLM_WL_groups_032009
From: Eric F. <ef...@ha...> - 2009年03月15日 03:57:41
Pablo Romero wrote:
> Im experiencing very poor performance when using the 'quiver' function over relatively large grids.
> Im using quiver to plot wind 'u,v' data over a lat/lon grid using basemap.
> 
> quiver performs decently over small lat/lon ranges, such as a bounding box of lat(0-30),lon(-120- -100), but when I try to plot larger areas (i.e. the entire globe), quiver causes a very large pause. through some debugging of quiver.py, I narrowed down the performance lag to the "set_vertices" function call within the "draw()" function in the quiver class. as a test, I printed 'len(vert)' in order to see the vertice array length that was causing problems...it seems that Im getting vertice counts in the high thousands, and quiver seems to struggle with this. 
> 
> should quiver be able to easily handle such a large amount of vertices?
What version of matplotlib are you using, and on what platform?
How long is the pause, and for how many vectors?
I presume you are referring to the set_verts() method which is inherited 
from collections.PolyCollection. It is using a list comprehension to 
loop over the vectors, making a path for each, so I would not expect it 
to be particularly quick; but whether it is unreasonable, or whether it 
can be sped up reasonably easily, I don't know.
> 
> 
> A secondary question:
> the method Im using to create my X,Y,U,V arrays is creating 'larger-than-necessary' X,Y arrays; i.e., Im not plotting the U,V vectors at each lat&lon point, Im 'skipping' over 'every-nth-point', so my U,V arrays are equal in size to my X,Y arrays, but have many empty elements. 
> 
> Unfortunately, the array data is being imported from an external program (named 'GRADS'), so I cannot prevent these arrays from being 'oversized' upon their creation.
> 
> example:
> for a (10 degree lat)x(10 degree lon) area, I might have arrays like this:
> 
> X='[0,0.5,1.0,1.5,2.0,2.5,...10.0],[0,0.5,...10],...[0.0,0.5,...10.0]'
> Y='[0,0.5,1.0,1.5,2.0,2.5,...10.0],[0,0.5,...10],...[0.0,0.5,...10.0]'
> U='[--,--,0.40,--,--,0.15,...0.30],[--,--,0.25,--,--...,0.12],...[--,--,0.50,...10.0]'
> V='[--,--,0.30,--,--,0.25,...0.40],[--,--,0.25,--,--...,0.12],...[--,--,0.50,...10.0]'
> 
> these values are completely inaccurate and are meant just to illustrate the fact that I have many 'skipped' values in my U,V arrays, and I have oversized X,Y arrays that cover the 10x10 lat/lon grid...
> 
> So, what I want to do is create NEW X,Y,U,V arrays or remove elements from these existing X,Y,U,V arrays, so that:
> 1) only valid, "non-empty" values will exist in my U,V arrays..and
> 2) the only values that exist in X,Y are those that correspond to valid points in the U,V arrays...
> 
> Im not very experienced with python/matplotlib, so I dont know what would be the best way to iterate over these 4 arrays and remove the empty invalid elements (or copy the valid elements into new arrays). How can I go about shortening these arrays?
>
Assuming your X, Y, U, V are all masked arrays or ndarrays of the same 
shape, you can use
from matplotlib.cbook import delete_masked_points
x,y,u,v = delete_masked_points(X.ravel(), Y.ravel(). U.ravel(), V.ravel())
The Barbs class in quiver.py uses this function; Quiver could be 
modified to use it, with the loss of a bit of functionality that I 
suspect no one is using anyway.
All the .ravel() method calls are needed only if the arrays are 2-D or 
higher.
> Im hoping that with less points in my X,Y arrays, that quiver will perform faster since it isnt wasting time trying to process X,Y points where U,V are empty).
>
Let us know how much difference it makes, and tell us what the initial 
and modified number of vectors is.
Eric
From: Eric F. <ef...@ha...> - 2009年03月15日 03:33:52
per freem wrote:
> hi all,
> 
> i'm trying to generate a very simple plot, where only the left y axis 
> and the bottom x axis are present. i.e. there is no top x axis or right 
> y axis... this is the default for many plotting packages. in matlab, one 
> can do this as follows:
> 
> >> x = rand(1,100);
> >> hist(x)
> >> set(gca, 'Box', 'off', 'LineWidth', 1);
> 
> so the set(gca, 'Box', 'off'...) command does the job. what's the 
> analogous matplotlib command? i would like to do this preferably without 
> any external packages.
There is no analogous command, despite many requests such as yours. 
Recipes for getting this effect have been posted to the list, though. 
See also 
http://matplotlib.sourceforge.net/examples/pylab_examples/manual_axis.html.
Making axes more flexible, to handle your case and others such as axes 
crossing in the middle of a figure, is on the wish list, but turns out 
to require quite a bit of work--more than one might expect.
Eric
From: Pablo R. <rom...@ho...> - 2009年03月15日 03:29:37
Im experiencing very poor performance when using the 'quiver' function over relatively large grids.
Im using quiver to plot wind 'u,v' data over a lat/lon grid using basemap.
 
quiver performs decently over small lat/lon ranges, such as a bounding box of lat(0-30),lon(-120- -100), but when I try to plot larger areas (i.e. the entire globe), quiver causes a very large pause. through some debugging of quiver.py, I narrowed down the performance lag to the "set_vertices" function call within the "draw()" function in the quiver class. as a test, I printed 'len(vert)' in order to see the vertice array length that was causing problems...it seems that Im getting vertice counts in the high thousands, and quiver seems to struggle with this. 
 
should quiver be able to easily handle such a large amount of vertices?
 
 
A secondary question:
the method Im using to create my X,Y,U,V arrays is creating 'larger-than-necessary' X,Y arrays; i.e., Im not plotting the U,V vectors at each lat&lon point, Im 'skipping' over 'every-nth-point', so my U,V arrays are equal in size to my X,Y arrays, but have many empty elements. 
 
Unfortunately, the array data is being imported from an external program (named 'GRADS'), so I cannot prevent these arrays from being 'oversized' upon their creation.
 
example:
for a (10 degree lat)x(10 degree lon) area, I might have arrays like this:
 
X='[0,0.5,1.0,1.5,2.0,2.5,...10.0],[0,0.5,...10],...[0.0,0.5,...10.0]'
Y='[0,0.5,1.0,1.5,2.0,2.5,...10.0],[0,0.5,...10],...[0.0,0.5,...10.0]'
U='[--,--,0.40,--,--,0.15,...0.30],[--,--,0.25,--,--...,0.12],...[--,--,0.50,...10.0]'
V='[--,--,0.30,--,--,0.25,...0.40],[--,--,0.25,--,--...,0.12],...[--,--,0.50,...10.0]'
 
these values are completely inaccurate and are meant just to illustrate the fact that I have many 'skipped' values in my U,V arrays, and I have oversized X,Y arrays that cover the 10x10 lat/lon grid...
 
So, what I want to do is create NEW X,Y,U,V arrays or remove elements from these existing X,Y,U,V arrays, so that:
1) only valid, "non-empty" values will exist in my U,V arrays..and
2) the only values that exist in X,Y are those that correspond to valid points in the U,V arrays...
 
Im not very experienced with python/matplotlib, so I dont know what would be the best way to iterate over these 4 arrays and remove the empty invalid elements (or copy the valid elements into new arrays). How can I go about shortening these arrays?
 
Im hoping that with less points in my X,Y arrays, that quiver will perform faster since it isnt wasting time trying to process X,Y points where U,V are empty).
 
Please help,
P.Romero
_________________________________________________________________
Hotmail® is up to 70% faster. Now good news travels really fast. 
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009
From: per f. <per...@gm...> - 2009年03月14日 17:22:17
hi all,
i have a set of about 100-500 points that i'd like to color in different
colors. i tried the following, using the c= argument to the scatter command:
x = rand(200)
scatter(x, x, c=xrange(1,201))
however, only a handful of colors seem to be used and the points look very
similar. what i am looking for is a different color for every point -- it
can even be different shades, as in this example:
http://matplotlib.sourceforge.net/examples/pylab_examples/ellipse_collection.html
does anyone know how to create this?
also, more complex, is there a way to do this where every point gets not
only a different color but a different symbol? e.g. '^', 's', 'x', etc. ? i
know there aren't 200 different symbols but it'd be nice if it cycled
through the different symbols as much as possible (e.g. one point might be
blue '^' and another might be red '^') to distinguish the points
thanks.
From: Jeff W. <js...@fa...> - 2009年03月14日 13:24:00
Timothée Lecomte wrote:
> Jeff Whitaker wrote:
>> Jeff Whitaker wrote:
>>> Timothée Lecomte wrote:
>>>> Dear all,
>>>>
>>>> I am using matplotlib with a great pleasure, and I enjoy its 
>>>> capabilities.
>>>> I have recently attended a conference where the invited speaker 
>>>> showed great visualizations of arrays from both experiments and 
>>>> simulations. His plots were basically looking like those produced 
>>>> by imshow, that is a luminance array rendered as a colormap image, 
>>>> but with the additionnal use of a shading, which gives a really 
>>>> great feeling to the image. You can feel the height of each part of 
>>>> the image.
>>>>
>>>> I have tried to find what software could have produced such a plot, 
>>>> and found the ReliefPlot function of Mathematica, which has 
>>>> precisely this purpose : rendering a colormap image from an array 
>>>> with a shading to give the perception of relief.
>>>>
>>>> The documentation and its examples are self-explanatory :
>>>> http://reference.wolfram.com/mathematica/ref/ReliefPlot.html
>>>> (look in particular at the first "neat example" at the bottom of 
>>>> that page)
>>>>
>>>> The two "live" demonstrations illustrate this plot style quite well 
>>>> too :
>>>> http://demonstrations.wolfram.com/ReliefShadedElevationMap/
>>>> http://demonstrations.wolfram.com/VoronoiImage/
>>>>
>>>> So here are my questions :
>>>> Is there a trick to generate an image with such a shading in 
>>>> matplotlib ?
>>>> If not, do you know of a python tool that could help ?
>>>> Where could I start if I want to code it myself in matplotlib ?
>>>>
>>>> Thanks for your help.
>>>>
>>>> Best regards,
>>>>
>>>> Timothée Lecomte
>>>>
>>>> 
>>>
>>> Timothée: There is nothing built-in, but it would be a nice thing 
>>> to have. Here's a proof-of-concept hack that follows the approach 
>>> used in the Generic Mapping Tools (explained here 
>>> http://www.seismo.ethz.ch/gmt/doc/html/tutorial/node70.html), with 
>>> some code borrowed from http://www.langarson.com.au/blog/?p=14. 
>>> It's very rough, but if it looks promising to you I can try to 
>>> polish it.
>>>
>>> -Jeff
>>
>> Found a bug, here's a fixed version.
>>
>> -Jeff
>>
> Hi Jeff,
>
> Sure it looks promising ! The example you provided is very nice. I 
> will try on my own data on Monday, and I'll let you know if it gives a 
> good result too. Thank you very much for that very fast hack !
>
> Best regards,
>
> Timothée
>
>
Timothée: I've added this capability in svn, along with an example 
(shading_example.py) to show how to use it. Thanks for suggesting it.
-Jeff
From: Eric F. <ef...@ha...> - 2009年03月14日 05:39:52
Thomas Robitaille wrote:
>>> It looks like rotation/translation should be easy to do with 
>>> Affine2D, so I tried using it, but I can't seem to get it to work as 
>>> expected - here is an example of how I am using it:
>>
>> Based on a quick look at image.py and _image.cpp, it appears that 
>> there is a low-level capability to rotate an image in the latter, but 
>> no support at higher levels. It also looks to me like adding that 
>> support would not be trivial--doing it right would take more than just 
>> calling the low-level apply_rotation method. Mike D. would be the 
>> expert on this, though.
> 
> Does this mean that the transform= keyword has no effect on imshow in 
> general?
It does look like it is ignored. It is a kwarg for Artists that is not 
supported by all. The fact that one can specify it and get no feedback 
is a bug.
> 
> I attempted to use the pcolormesh() method, which worked, but is 
> impractical, as a 1000x1000 image produces a 300Mb EPS file when plotted 
> in this way.
There is some infrastructure for handling this via selective 
rasterization of artists, but I can never remember exactly what its 
status is; I don't see anything in the examples. The topic comes up on 
the list at perhaps 6-month intervals. Personally, I would very much 
like to see the selective rasterization capability fully developed and 
exposed, complete with documentation and examples; it is important for 
exactly the reason you note above. It is not something I will be able 
to work on myself, unfortunately.
Eric
From: Ryan M. <rm...@gm...> - 2009年03月14日 01:50:29
On Fri, Mar 13, 2009 at 5:18 PM, per freem <per...@gm...> wrote:
> hi all,
>
> what's the most efficient / preferred python way of parsing tab separated
> data into arrays? for example if i have a file containing two columns one
> corresponding to names the other numbers:
>
> col1 \t col 2
> joe \t 12.3
> jane \t 155.0
>
> i'd like to parse into an array() such that i can do: mydata[:, 0] and
> mydata[:, 1] to easily access all the columns.
>
> right now i can iterate through the file, parse it manually using the
> split('\t') command and construct a list out of it, then convert it to
> arrays. but there must be a better way?
>
> also, my first column is just a name, and so it is variable in length -- is
> there still a way to store it as an array so i can access: mydata[:, 0] to
> get all the names (as a list)?
>
>
Try matplotlib.mlab.csv2rec or numpy.loadtxt
Ryan
-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
Sent from: Norman Oklahoma United States.
From: Thomas R. <tho...@gm...> - 2009年03月14日 00:52:13
>> It looks like rotation/translation should be easy to do with 
>> Affine2D, so I tried using it, but I can't seem to get it to work 
>> as expected - here is an example of how I am using it:
>
> Based on a quick look at image.py and _image.cpp, it appears that 
> there is a low-level capability to rotate an image in the latter, 
> but no support at higher levels. It also looks to me like adding 
> that support would not be trivial--doing it right would take more 
> than just calling the low-level apply_rotation method. Mike D. 
> would be the expert on this, though.
Does this mean that the transform= keyword has no effect on imshow in 
general?
I tried doing a simple image translation, and this didn't work either:
import numpy as np
from matplotlib.pyplot import *
from matplotlib.transforms import Affine2D
im = np.random.random((10,10))
tr = Affine2D().translate(10.,10.)
fig = figure()
ax = fig.add_subplot(111)
ax.imshow(im,transform=tr)
fig.canvas.draw()
I attempted to use the pcolormesh() method, which worked, but is 
impractical, as a 1000x1000 image produces a 300Mb EPS file when 
plotted in this way.
Thanks,
Thomas
>
> Eric
>
>> import numpy as np
>> from matplotlib.pyplot import *
>> from matplotlib.transforms import Affine2D
>> im = np.random.random((10,10))
>> tr = Affine2D().rotate_deg(45.)
>> fig = figure()
>> ax = fig.add_subplot(111)
>> ax.imshow(im,transform=tr)
>> fig.canvas.draw()
>> Am I doing something wrong?
>> Thanks!
>> Thomas
>> On Mar 13, 2009, at 5:20 PM, Andrew Straw wrote:
>>> Eric Firing wrote:
>>>> Thomas Robitaille wrote:
>>>>> Hello,
>>>>>
>>>>> I was wondering whether there is a way to rotate a grayscale/
>>>>> colorscale when using imshow.
>>>>>
>>>>> I have been using PGPLOT (a fortran/c plotting library) for 
>>>>> many years
>>>>> now, and the equivalent to imshow is called PGGRAY (or PGIMAG). 
>>>>> One of
>>>>> the arguments this function takes is a 6-element array TR which 
>>>>> is a
>>>>> transformation matrix. From the PGPLOT documentation:
>>>>>
>>>>> "The transformation matrix TR is used to calculate the world
>>>>> coordinates of the center of the "cell" that represents each array
>>>>> element. The world coordinates of the center of the cell 
>>>>> corresponding
>>>>> to array element A(I,J) are given by:
>>>>> X = TR(1) + TR(2)*I + TR(3)*J
>>>>> Y = TR(4) + TR(5)*I + TR(6)*J"
>>>>
>>>> You could do this with the Axes.pcolormesh method. You could 
>>>> start with
>>>> an unrotated grid (generated by meshgrid, for example), apply your
>>>> rotation, and use that transformed grid in pcolormesh. Note that
>>>> pcolormesh requires the grid for the cell boundaries, not centers.
>>>>
>>>
>>> It should work with imshow() as well if you can set the affine 
>>> component
>>> of the transform to the desired values. Which it looks like you 
>>> can in
>>> Affine2D(). (The affine matrix is the elements of TR listed 
>>> above, it
>>> appears.)
>>>
>>> I have not tried to do this, however -- just saying that I think 
>>> it's
>>> possible.
>>>
>>> -Andrew
>
From: Eric F. <ef...@ha...> - 2009年03月14日 00:46:15
Thomas Robitaille wrote:
> It looks like rotation/translation should be easy to do with Affine2D, 
> so I tried using it, but I can't seem to get it to work as expected - 
> here is an example of how I am using it:
Based on a quick look at image.py and _image.cpp, it appears that there 
is a low-level capability to rotate an image in the latter, but no 
support at higher levels. It also looks to me like adding that support 
would not be trivial--doing it right would take more than just calling 
the low-level apply_rotation method. Mike D. would be the expert on 
this, though.
Eric
> 
> import numpy as np
> from matplotlib.pyplot import *
> from matplotlib.transforms import Affine2D
> 
> im = np.random.random((10,10))
> tr = Affine2D().rotate_deg(45.)
> 
> fig = figure()
> ax = fig.add_subplot(111)
> ax.imshow(im,transform=tr)
> fig.canvas.draw()
> 
> Am I doing something wrong?
> 
> Thanks!
> 
> Thomas
> 
> On Mar 13, 2009, at 5:20 PM, Andrew Straw wrote:
> 
>> Eric Firing wrote:
>>> Thomas Robitaille wrote:
>>>> Hello,
>>>>
>>>> I was wondering whether there is a way to rotate a grayscale/
>>>> colorscale when using imshow.
>>>>
>>>> I have been using PGPLOT (a fortran/c plotting library) for many years
>>>> now, and the equivalent to imshow is called PGGRAY (or PGIMAG). One of
>>>> the arguments this function takes is a 6-element array TR which is a
>>>> transformation matrix. From the PGPLOT documentation:
>>>>
>>>> "The transformation matrix TR is used to calculate the world
>>>> coordinates of the center of the "cell" that represents each array
>>>> element. The world coordinates of the center of the cell corresponding
>>>> to array element A(I,J) are given by:
>>>> X = TR(1) + TR(2)*I + TR(3)*J
>>>> Y = TR(4) + TR(5)*I + TR(6)*J"
>>>
>>> You could do this with the Axes.pcolormesh method. You could start with
>>> an unrotated grid (generated by meshgrid, for example), apply your
>>> rotation, and use that transformed grid in pcolormesh. Note that
>>> pcolormesh requires the grid for the cell boundaries, not centers.
>>>
>>
>> It should work with imshow() as well if you can set the affine component
>> of the transform to the desired values. Which it looks like you can in
>> Affine2D(). (The affine matrix is the elements of TR listed above, it
>> appears.)
>>
>> I have not tried to do this, however -- just saying that I think it's
>> possible.
>>
>> -Andrew
> 
From: João L. S. <js...@fc...> - 2009年03月13日 22:39:23
per freem wrote:
> hi all,
> 
> what's the most efficient / preferred python way of parsing tab 
> separated data into arrays? for example if i have a file containing two 
Check out the python csv module. Documentation at
http://docs.python.org/library/csv.html
JLS
From: Timothée L. <tim...@lp...> - 2009年03月13日 22:24:20
Jeff Whitaker wrote:
> Jeff Whitaker wrote:
>> Timothée Lecomte wrote:
>>> Dear all,
>>>
>>> I am using matplotlib with a great pleasure, and I enjoy its 
>>> capabilities.
>>> I have recently attended a conference where the invited speaker 
>>> showed great visualizations of arrays from both experiments and 
>>> simulations. His plots were basically looking like those produced by 
>>> imshow, that is a luminance array rendered as a colormap image, but 
>>> with the additionnal use of a shading, which gives a really great 
>>> feeling to the image. You can feel the height of each part of the 
>>> image.
>>>
>>> I have tried to find what software could have produced such a plot, 
>>> and found the ReliefPlot function of Mathematica, which has 
>>> precisely this purpose : rendering a colormap image from an array 
>>> with a shading to give the perception of relief.
>>>
>>> The documentation and its examples are self-explanatory :
>>> http://reference.wolfram.com/mathematica/ref/ReliefPlot.html
>>> (look in particular at the first "neat example" at the bottom of 
>>> that page)
>>>
>>> The two "live" demonstrations illustrate this plot style quite well 
>>> too :
>>> http://demonstrations.wolfram.com/ReliefShadedElevationMap/
>>> http://demonstrations.wolfram.com/VoronoiImage/
>>>
>>> So here are my questions :
>>> Is there a trick to generate an image with such a shading in 
>>> matplotlib ?
>>> If not, do you know of a python tool that could help ?
>>> Where could I start if I want to code it myself in matplotlib ?
>>>
>>> Thanks for your help.
>>>
>>> Best regards,
>>>
>>> Timothée Lecomte
>>>
>>> 
>>
>> Timothée: There is nothing built-in, but it would be a nice thing to 
>> have. Here's a proof-of-concept hack that follows the approach used 
>> in the Generic Mapping Tools (explained here 
>> http://www.seismo.ethz.ch/gmt/doc/html/tutorial/node70.html), with 
>> some code borrowed from http://www.langarson.com.au/blog/?p=14. It's 
>> very rough, but if it looks promising to you I can try to polish it.
>>
>> -Jeff
>
> Found a bug, here's a fixed version.
>
> -Jeff
>
Hi Jeff,
Sure it looks promising ! The example you provided is very nice. I will 
try on my own data on Monday, and I'll let you know if it gives a good 
result too. Thank you very much for that very fast hack !
Best regards,
Timothée
From: per f. <per...@gm...> - 2009年03月13日 22:18:41
hi all,
what's the most efficient / preferred python way of parsing tab separated
data into arrays? for example if i have a file containing two columns one
corresponding to names the other numbers:
col1 \t col 2
joe \t 12.3
jane \t 155.0
i'd like to parse into an array() such that i can do: mydata[:, 0] and
mydata[:, 1] to easily access all the columns.
right now i can iterate through the file, parse it manually using the
split('\t') command and construct a list out of it, then convert it to
arrays. but there must be a better way?
also, my first column is just a name, and so it is variable in length -- is
there still a way to store it as an array so i can access: mydata[:, 0] to
get all the names (as a list)?
thank you.
From: Thomas R. <tho...@gm...> - 2009年03月13日 21:53:51
Thanks to both of you for your help! I had spotted the transform 
argument in imshow, but didn't manage to find any information about 
how to use it. The Affine2D method looks like it will help, so I 
should be all set now.
Thanks!
Thomas
On Mar 13, 2009, at 5:20 PM, Andrew Straw wrote:
> Eric Firing wrote:
>> Thomas Robitaille wrote:
>>> Hello,
>>>
>>> I was wondering whether there is a way to rotate a grayscale/
>>> colorscale when using imshow.
>>>
>>> I have been using PGPLOT (a fortran/c plotting library) for many 
>>> years
>>> now, and the equivalent to imshow is called PGGRAY (or PGIMAG). 
>>> One of
>>> the arguments this function takes is a 6-element array TR which is a
>>> transformation matrix. From the PGPLOT documentation:
>>>
>>> "The transformation matrix TR is used to calculate the world
>>> coordinates of the center of the "cell" that represents each array
>>> element. The world coordinates of the center of the cell 
>>> corresponding
>>> to array element A(I,J) are given by:
>>> X = TR(1) + TR(2)*I + TR(3)*J
>>> Y = TR(4) + TR(5)*I + TR(6)*J"
>>
>> You could do this with the Axes.pcolormesh method. You could start 
>> with
>> an unrotated grid (generated by meshgrid, for example), apply your
>> rotation, and use that transformed grid in pcolormesh. Note that
>> pcolormesh requires the grid for the cell boundaries, not centers.
>>
>
> It should work with imshow() as well if you can set the affine 
> component
> of the transform to the desired values. Which it looks like you can in
> Affine2D(). (The affine matrix is the elements of TR listed above, it
> appears.)
>
> I have not tried to do this, however -- just saying that I think it's
> possible.
>
> -Andrew
From: Thomas R. <tho...@gm...> - 2009年03月13日 21:46:50
It looks like rotation/translation should be easy to do with Affine2D, 
so I tried using it, but I can't seem to get it to work as expected - 
here is an example of how I am using it:
import numpy as np
from matplotlib.pyplot import *
from matplotlib.transforms import Affine2D
im = np.random.random((10,10))
tr = Affine2D().rotate_deg(45.)
fig = figure()
ax = fig.add_subplot(111)
ax.imshow(im,transform=tr)
fig.canvas.draw()
Am I doing something wrong?
Thanks!
Thomas
On Mar 13, 2009, at 5:20 PM, Andrew Straw wrote:
> Eric Firing wrote:
>> Thomas Robitaille wrote:
>>> Hello,
>>>
>>> I was wondering whether there is a way to rotate a grayscale/
>>> colorscale when using imshow.
>>>
>>> I have been using PGPLOT (a fortran/c plotting library) for many 
>>> years
>>> now, and the equivalent to imshow is called PGGRAY (or PGIMAG). 
>>> One of
>>> the arguments this function takes is a 6-element array TR which is a
>>> transformation matrix. From the PGPLOT documentation:
>>>
>>> "The transformation matrix TR is used to calculate the world
>>> coordinates of the center of the "cell" that represents each array
>>> element. The world coordinates of the center of the cell 
>>> corresponding
>>> to array element A(I,J) are given by:
>>> X = TR(1) + TR(2)*I + TR(3)*J
>>> Y = TR(4) + TR(5)*I + TR(6)*J"
>>
>> You could do this with the Axes.pcolormesh method. You could start 
>> with
>> an unrotated grid (generated by meshgrid, for example), apply your
>> rotation, and use that transformed grid in pcolormesh. Note that
>> pcolormesh requires the grid for the cell boundaries, not centers.
>>
>
> It should work with imshow() as well if you can set the affine 
> component
> of the transform to the desired values. Which it looks like you can in
> Affine2D(). (The affine matrix is the elements of TR listed above, it
> appears.)
>
> I have not tried to do this, however -- just saying that I think it's
> possible.
>
> -Andrew
From: Andrew S. <str...@as...> - 2009年03月13日 21:20:16
Eric Firing wrote:
> Thomas Robitaille wrote:
>> Hello,
>>
>> I was wondering whether there is a way to rotate a grayscale/ 
>> colorscale when using imshow.
>>
>> I have been using PGPLOT (a fortran/c plotting library) for many years 
>> now, and the equivalent to imshow is called PGGRAY (or PGIMAG). One of 
>> the arguments this function takes is a 6-element array TR which is a 
>> transformation matrix. From the PGPLOT documentation:
>>
>> "The transformation matrix TR is used to calculate the world 
>> coordinates of the center of the "cell" that represents each array 
>> element. The world coordinates of the center of the cell corresponding 
>> to array element A(I,J) are given by:
>> X = TR(1) + TR(2)*I + TR(3)*J
>> Y = TR(4) + TR(5)*I + TR(6)*J"
> 
> You could do this with the Axes.pcolormesh method. You could start with 
> an unrotated grid (generated by meshgrid, for example), apply your 
> rotation, and use that transformed grid in pcolormesh. Note that 
> pcolormesh requires the grid for the cell boundaries, not centers.
> 
It should work with imshow() as well if you can set the affine component
of the transform to the desired values. Which it looks like you can in
Affine2D(). (The affine matrix is the elements of TR listed above, it
appears.)
I have not tried to do this, however -- just saying that I think it's
possible.
-Andrew
From: Jeff W. <js...@fa...> - 2009年03月13日 21:10:08
Attachments: hillshade.py
Jeff Whitaker wrote:
> Timothée Lecomte wrote:
>> Dear all,
>>
>> I am using matplotlib with a great pleasure, and I enjoy its 
>> capabilities.
>> I have recently attended a conference where the invited speaker 
>> showed great visualizations of arrays from both experiments and 
>> simulations. His plots were basically looking like those produced by 
>> imshow, that is a luminance array rendered as a colormap image, but 
>> with the additionnal use of a shading, which gives a really great 
>> feeling to the image. You can feel the height of each part of the image.
>>
>> I have tried to find what software could have produced such a plot, 
>> and found the ReliefPlot function of Mathematica, which has precisely 
>> this purpose : rendering a colormap image from an array with a 
>> shading to give the perception of relief.
>>
>> The documentation and its examples are self-explanatory :
>> http://reference.wolfram.com/mathematica/ref/ReliefPlot.html
>> (look in particular at the first "neat example" at the bottom of that 
>> page)
>>
>> The two "live" demonstrations illustrate this plot style quite well 
>> too :
>> http://demonstrations.wolfram.com/ReliefShadedElevationMap/
>> http://demonstrations.wolfram.com/VoronoiImage/
>>
>> So here are my questions :
>> Is there a trick to generate an image with such a shading in 
>> matplotlib ?
>> If not, do you know of a python tool that could help ?
>> Where could I start if I want to code it myself in matplotlib ?
>>
>> Thanks for your help.
>>
>> Best regards,
>>
>> Timothée Lecomte
>>
>> 
>
> Timothée: There is nothing built-in, but it would be a nice thing to 
> have. Here's a proof-of-concept hack that follows the approach used 
> in the Generic Mapping Tools (explained here 
> http://www.seismo.ethz.ch/gmt/doc/html/tutorial/node70.html), with 
> some code borrowed from http://www.langarson.com.au/blog/?p=14. It's 
> very rough, but if it looks promising to you I can try to polish it.
>
> -Jeff
Found a bug, here's a fixed version.
-Jeff
-- 
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jef...@no...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
From: Eric F. <ef...@ha...> - 2009年03月13日 20:48:40
Thomas Robitaille wrote:
> Hello,
> 
> I was wondering whether there is a way to rotate a grayscale/ 
> colorscale when using imshow.
> 
> I have been using PGPLOT (a fortran/c plotting library) for many years 
> now, and the equivalent to imshow is called PGGRAY (or PGIMAG). One of 
> the arguments this function takes is a 6-element array TR which is a 
> transformation matrix. From the PGPLOT documentation:
> 
> "The transformation matrix TR is used to calculate the world 
> coordinates of the center of the "cell" that represents each array 
> element. The world coordinates of the center of the cell corresponding 
> to array element A(I,J) are given by:
> X = TR(1) + TR(2)*I + TR(3)*J
> Y = TR(4) + TR(5)*I + TR(6)*J"
You could do this with the Axes.pcolormesh method. You could start with 
an unrotated grid (generated by meshgrid, for example), apply your 
rotation, and use that transformed grid in pcolormesh. Note that 
pcolormesh requires the grid for the cell boundaries, not centers.
Eric
> 
> This is actually the same as the ImageMatrix element in the Postscript 
> language:
> 
> "ImageMatrix array (Required) An array of six numbers defining a 
> transformation from user
> space to image space." (http://www.adobe.com/devnet/postscript/pdfs/PLRM.pdf 
> , page 298)
> 
> This allows arbitrary rotation/translation of the image to plotting 
> without any loss in quality for vector graphics formats (EPS, PDF, SVG).
> 
> So far, I have found that imshow has an 'extend' keyword, which is the 
> equivalent of four of the matrix elements, but there is no way to 
> specify the rotation. Is there such a feature in matplotlib already? 
> If not, would it be possible to implement it?
> 
> Just to be clear, I am not talking about rotating with some kind of 
> interpolation, which would degrade the image (this can be done with 
> PIL). What I want is to be able to specify a transformation matrix 
> which includes rotation, which means that there is no resampling done 
> if I save my plot in a vector graphics format.
> 
> Thanks in advance for any help!
> 
> Thomas
> 
> ------------------------------------------------------------------------------
> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
> software that enables intelligent coding and step-through debugging.
> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
15 messages has been excluded from this view by a project administrator.

Showing results of 394

<< < 1 .. 8 9 10 11 12 .. 16 > >> (Page 10 of 16)
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 によって変換されたページ (->オリジナル) /