Re: [Matplotlib-users] Align Text (Relative)

2009-08-14 Thread jason-sage
Andrew Kelly wrote:
> I am currently using the annotate() method for my data points and I 
> was curious if there is a way to center a line of text relative to a 
> line of text below it.  I am currently using two annotate() function 
> calls in a row (I need the text to be different colors) but I need the 
> first one to act as a title for the second (i.e. so I want it centered 
> relative to the one below.)  I have tried to use the length of the 
> second bit of text to center but I just cannot seem to do it.  The 
> code looks sort of like this:
>
> import matplotlib.pyplot as plt
> ...
> annotateTitle='Title'
> annotateText='Blah, Blah, Blah'
> plt.annotate(annotateTitle, xy=(1,1), xytext=(20,50), xycoords='data', 
> textcoords='offset points')
> plt.annotate(annotateText, xy=(1,1), xytext=(20,20), xycoords='data', 
> textcoords='offset points', size='small', color='black')
>


In the example at the bottom of 
http://matplotlib.sourceforge.net/users/annotations.html

you see an example where the horizontalalignment is specified.  Can you 
just do something like the following?


plt.annotate(annotateTitle, xy=(1,1), xytext=(20,50), xycoords='data', 
textcoords='offset points', horizontalalignment='center')
plt.annotate(annotateText, xy=(1,1), xytext=(20,20), xycoords='data', 
textcoords='offset points', size='small', color='black', 
horizontalalignment='center')


You also see examples of the alignment parameters at 
http://matplotlib.sourceforge.net/examples/pylab_examples/annotation_demo.html#pylab-examples-annotation-demo

Thanks,

Jason


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] colormap creation

2009-08-14 Thread P.R.
Jeff,
Ok, so this is what I was trying to achieve...

c=['#6C9F7B','#783F68','#F4F4F2','#22F322','#F3F322','#F3']
mycm=mpl.colors.LinearSegmentedColormap.from_list('mycm',c)
plt.imshow(rand(10,10),cmap=mycm,interpolation='nearest')
colorbar()
plt.show()

That was the initial goal; being able to quickly create the cmap based on
some basic colors.
from there, I can optionally play with the mycm._segmentdata dictionary in
order to fine-tune the color spread.

...the documentation on the 'LinearSegmentedColormap.from_list()' method is
very brief, 
and there wasn't an example, so I didn't see it right away...

Anyway, problem solved.
Sorry for the confusion, & thanks again for the help

P.Romero

-Original Message-
From: Jeff Whitaker [mailto:jsw...@fastmail.fm] 
Sent: 2009-08-14 6:35 PM
To: P.R.
Subject: Re: [Matplotlib-users] colormap creation

P.R. wrote:
> Jeff,
> Thanks for pointing me to that example.
> I was basically manually performing the same operations as those listed in
> the example.
> however, like I said before, its been slow going, since I have to manually
> edit the ranges & adjust 'linear spread' of each color.
> It's a trial & error process...
>
> Im clear on how the rgb dictionary works; 
> I guess my problem/question was more on how to automate some of the work
> involved in creating the rgb dictionary.
>
> Example:
> Supposing that I have a rough idea of what color sequence I want, 
> let's say, 
>
> black 
> blue
> yellow
> red
> purple
>
> ... yet Im not sure about the exact values or 'tones' of these colors... 
> (this is an arbitrary example, let's assume that a similar cmap doesn't
> already exist in mpl)
>
> - I'd like to have an automatic method to easily create a preliminary,
> 'rough draft' rgb dictionary based on the rgb values for my basic
colors... 
> this way, I can quickly create a 'prototype' dictionary that I can then
> modify & adjust to suit my needs.
>
> so, a 'colormap generator' that takes a set of rgb values as input, and
> create the value ranges within the rgb dictionary automatically...
>
> Any ideas?
>   

Nope, sorry. 

-Jeff
> Thanks,
> P.Romero
>
> -Original Message-
> From: Jeff Whitaker [mailto:jsw...@fastmail.fm] 
> Sent: 2009-08-14 5:29 PM
> To: P.R.
> Cc: matplotlib-users@lists.sourceforge.net
> Subject: Re: [Matplotlib-users] colormap creation
>
> P.R. wrote:
>   
>> Can someone please recommend a (semi) automatic way to create the rgb
>> dictionaries needed for colormap creation?
>> Basically, I have a 'general' idea of how I want my colors ordered, but
Im
>> finding it difficult to create the smooth transitions by manually editing
>> the rgb dictionary for my custom colormap...the trial & error process is
>> tedious & not very accurate...
>>
>> How were the matplotlib colormaps created?
>> Were they created manually or programmatically?
>> Was it done using a random color selection?
>>
>> Please help,
>> Thanks,
>> P.Romero
>>   
>> 
>
> P.R.:  If you haven't already, you should look at the custom_cmap.py 
> example.
>
> -Jeff
>
>   


-- 
Jeffrey S. Whitaker Phone  : (303)497-6313
Meteorologist   FAX: (303)497-6449
NOAA/OAR/PSD  R/PSD1Email  : jeffrey.s.whita...@noaa.gov
325 BroadwayOffice : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg



--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] colormap creation

2009-08-14 Thread Jeff Whitaker
P.R. wrote:
> Can someone please recommend a (semi) automatic way to create the rgb
> dictionaries needed for colormap creation?
> Basically, I have a 'general' idea of how I want my colors ordered, but Im
> finding it difficult to create the smooth transitions by manually editing
> the rgb dictionary for my custom colormap...the trial & error process is
> tedious & not very accurate...
>
> How were the matplotlib colormaps created?
> Were they created manually or programmatically?
> Was it done using a random color selection?
>
> Please help,
> Thanks,
> P.Romero
>   

P.R.:  If you haven't already, you should look at the custom_cmap.py 
example.

-Jeff

-- 
Jeffrey S. Whitaker Phone  : (303)497-6313
Meteorologist   FAX: (303)497-6449
NOAA/OAR/PSD  R/PSD1Email  : jeffrey.s.whita...@noaa.gov
325 BroadwayOffice : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] colormap creation

2009-08-14 Thread P.R.
Can someone please recommend a (semi) automatic way to create the rgb
dictionaries needed for colormap creation?
Basically, I have a 'general' idea of how I want my colors ordered, but Im
finding it difficult to create the smooth transitions by manually editing
the rgb dictionary for my custom colormap...the trial & error process is
tedious & not very accurate...

How were the matplotlib colormaps created?
Were they created manually or programmatically?
Was it done using a random color selection?

Please help,
Thanks,
P.Romero


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] mpl.colors.BoundaryNorm question

2009-08-14 Thread P.R.
Eric, 
Thanks, that worked...

I have a separate question about colormaps...
I'd also like to try creating my own custom colormap by modifying an
existing cmap, inserting/removing colors by changing the values in the rgb
dictionary...

How do I retrieve the actual rgb dictionary associated with, say, cm.jet?

Thanks,
P.Romero

-Original Message-
From: Eric Firing [mailto:efir...@hawaii.edu] 
Sent: 2009-08-14 12:49 PM
To: P.R.
Cc: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] mpl.colors.BoundaryNorm question

Eric Firing wrote:

It occurred to me after posting that imshow by default gives a 
misleading picture of the effect of the cmap and boundary norm.  To get 
a clear picture, add the "interpolation='nearest'" kwarg to the imshow call.

Eric

> 
> import numpy as np
> import matplotlib.pyplot as plt
> import matplotlib.colors as mcolors
> import matplotlib.cm as cm
> 
> 
> boundaries = np.linspace(20, 30, 11)
> colors = cm.spectral(np.linspace(0.3, 0.8, 10))
> cmap = mcolors.ListedColormap(colors)
> norm = mcolors.BoundaryNorm(boundaries, cmap.N)
> 
> z = 20 + np.random.rand(10,20)*10
> plt.imshow(z, cmap=cmap, norm=norm)
> plt.colorbar()
> plt.show()
> 


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] mpl.colors.BoundaryNorm question

2009-08-14 Thread Eric Firing
Eric Firing wrote:

It occurred to me after posting that imshow by default gives a 
misleading picture of the effect of the cmap and boundary norm.  To get 
a clear picture, add the "interpolation='nearest'" kwarg to the imshow call.

Eric

> 
> import numpy as np
> import matplotlib.pyplot as plt
> import matplotlib.colors as mcolors
> import matplotlib.cm as cm
> 
> 
> boundaries = np.linspace(20, 30, 11)
> colors = cm.spectral(np.linspace(0.3, 0.8, 10))
> cmap = mcolors.ListedColormap(colors)
> norm = mcolors.BoundaryNorm(boundaries, cmap.N)
> 
> z = 20 + np.random.rand(10,20)*10
> plt.imshow(z, cmap=cmap, norm=norm)
> plt.colorbar()
> plt.show()
> 

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] how do I get past show()

2009-08-14 Thread Alan G Isaac
On 8/14/2009 11:54 AM Dan Klinglesmith apparently wrote:
> I am writing a python script that is a continuous running script in which I 
> want to update a weather data plot. [...]

> I can make the plots but can not figure how to get past "show()".  

http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg12365.html

Oddly this is not in the FAQ is the documentation points to a missing item:
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.show

Alan Isaac

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] how do I get past show()

2009-08-14 Thread Dan Klinglesmith
I am writing a python script that is a continuous running script in which I 
want to update a weather data plot.  In other words I am collecting weather 
data (temperature, RH, winds, etc) on a regular basis and want to update a plot 
of the last 24 hours worth of data.

I can make the plots but can not figure how to get past "show()".  

Suggestions?

cheers, Dan

Daniel A. Klinglesmith III
Magdalena Ridge Observatory
New Mexico Tech
(575) 835-6802

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] 0.99.0-RC1 and the animation_blit_gtk2 example

2009-08-14 Thread Christophe Dupre
Thanks JJ, this works fairly well. 

I was wondering if the following would also be possible: at start up, draw all 
the minute bars in an invisible background, and on each update only display a 
subset of the background. 

Regards,

Christophe


-Original Message-
From: Jae-Joon Lee [mailto:lee.j.j...@gmail.com] 
Sent: 06 August 2009 17:01
To: Christophe Dupre
Cc: matplotlib-users
Subject: Re: [Matplotlib-users] 0.99.0-RC1 and the animation_blit_gtk2 example

Christophe,

Unfortunately, the background is always shifted by integer pixel. So, shift in 
data and shift in pixel have some offset and what you see is the accumulation 
of this offset.
And you have to manage the pixel and and data coordinates in sync.

For example, you may try to keep the original transform and calculate the pixel 
shift in this coordinate. This would work if you're not worried about the 
overflow.

The attached example solve this with different approach. However, dx_data in 
this approach is not constant but fluctuate, although its mean value should be 
one minute.

Regards,

-JJ



On Wed, Aug 5, 2009 at 7:48 AM, Christophe Dupre 
wrote:
> Hi JJ,
>
> Thanks for that. It works fairly well, but I've noticed that the graph 
> content (the candlesticks) move slightly faster than the x axis. I've added a 
> sleep(0.1) statement to slow things down, and we can see that at the start 
> the first bar is displayed at around 13:15 but by the times is gets to the 
> left, the same bar is then displayed at about 13:00.
>
> Do you have any suggestion on how to improve that?
>
> Apart from that, shifting the graph is quite fast. On my machine, I get a 
> frame rate of 30 FPS if I redraw both X and Y axis. The rate goes much higher 
> ( greater than 100 FPS) if I don't redraw the axis.
>
> Thanks,
>
> Christophe
>
>
> -Original Message-
> From: Jae-Joon Lee [mailto:lee.j.j...@gmail.com]
> Sent: 05 August 2009 03:36
> To: Christophe Dupre
> Cc: matplotlib-users
> Subject: Re: [Matplotlib-users] 0.99.0-RC1 and the animation_blit_gtk2 
> example
>
> On Tue, Aug 4, 2009 at 12:14 PM, Christophe 
> Dupre wrote:
>> Hello,
>>
>>
>>
>> I've been playing with the animation_blit_gtk2 example 
>> (http://matplotlib.sourceforge.net/examples/animation/animation_blit_
>> gtk2.html
>>
>> ) and the latest version of matplotlib version 0.99.0-RC1.
>>
>> I've modified the example so that it displays candlesticks moving 
>> towards the lelf. The example is attached if anybody is interested.
>>
>>
>>
>>
>>
>> In my example, I'm using 1 minute bars and therefore I would like to 
>> shift the graph by 1 minute instead of a few pixels. Is there a way 
>> to convert a time difference into pixels?
>>
>
> The "get_dx_data" method coverts a pixel offset to a data offset.
> So, what you need is just to invert it.
> This requires some knowledge of transformation, but I guess the code 
> is rather self-explanatory.
>
> For example,  something like below will work (sorry, I haven't 
> actually tested the code)
>
>    def get_dx_pixel(self, dx_data):
>        tp = self.ax.transData.transform_point
>        x0, y0 = tp((0, 0))
>        x1, y1 = tp((dx_data, 0))
>        return (x1-x0)
>
> Regards,
>
> -JJ
>
>>
>>
>> Thanks,
>>
>>
>>
>> Christophe
>>
>>
>>
>>
>>
>> -
>> - Let Crystal Reports handle the reporting - Free Crystal 
>> Reports 2008 30-Day trial. Simplify your report design, integration 
>> and deployment - and focus on what you do best, core application 
>> coding. Discover what's new with Crystal Reports now.  
>> http://p.sf.net/sfu/bobj-july 
>> ___
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.392 / Virus Database: 270.13.43/2281 - Release Date: 
> 08/04/09 05:57:00
>

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.392 / Virus Database: 270.13.44/2283 - Release Date: 08/05/09 
18:23:00
--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] trouble installing new matplotlib on mac os x

2009-08-14 Thread Jouni K . Seppänen
per freem  writes:

> i am trying to install matplotlib-0.99 on a mac os x machine, with the
> following  python:
>
> Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
> [GCC 4.0.1 (Apple Inc. build 5465)] on darwin

I think that's the system Python (/usr/bin/python), while the installer
package works with the framework Python (/usr/local/bin/python). See:

http://matplotlib.sourceforge.net/faq/installing_faq.html#os-x-questions
http://www.python.org/download/mac/
http://www.python.org/download/releases/2.5.4/

> i also cannot where the new version was installed. does anyone know
> where the files for the new matplotlib should be? they are not in
> /Library/Frameworks/Python2.5/ it seems.

It should be in

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages

> if i do:
>
> locate matplotlib | grep 0.99
>
> nothing comes up. i only see files related to the older matplotlib
> when i do "locate matplotlib" in the shell.

The locate database is only updated weekly (and that's assuming that you
keep your Mac running in the early hours in which the update is run by
default). Try

sudo periodic weekly

to update the database if you want locate to find recently created
files. The update can take quite some time.

> any ideas how i can install this?  i wanted to try the .egg
> installation with "easy_install" but when i do:
>
> easy_install matplotlib
>
> it matches to a 0.98 version of matplotlib, not 0.99.

easy_install can be really bothersome. If you have an easy-install.pth
file in your site-packages directory, edit it and remove references to
the old version of matplotlib.

-- 
Jouni K. Seppänen
http://www.iki.fi/jks


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] trouble installing new matplotlib on mac os x

2009-08-14 Thread per freem
hi all,

i am trying to install matplotlib-0.99 on a mac os x machine, with the
following  python:

Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin

using version 10.5.6 of mac os x. when i go to
http://sourceforge.net/projects/matplotlib/ it prompts me to download
matplotlib-0.99.0-py2.5-macosx10.5.dmg.  when i download this
installer and install it, it only lets me to install it in my mac
harddrive (I don't see any option to change the installation
location.)  installation goes through smoothly and in the end i get
the "installation successful" message.  however, only the older
version of matplotlib comes up when i do "import matplotlib". i also
cannot where the new version was installed. does anyone know where the
files for the new matplotlib should be? they are not in
/Library/Frameworks/Python2.5/ it seems.

if i do:

locate matplotlib | grep 0.99

nothing comes up. i only see files related to the older matplotlib
when i do "locate matplotlib" in the shell.
any ideas how i can install this?  i wanted to try the .egg
installation with "easy_install" but when i do:

easy_install matplotlib

it matches to a 0.98 version of matplotlib, not 0.99.

thanks for your help

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] mpl.colors.BoundaryNorm question

2009-08-14 Thread Eric Firing
P.R. wrote:
> Hi,
> I'd like to generate a colormap index based on an array of levels & using an
> existing colormap (Spectral).
> However, Id like the cmap index to start at the 0.3 value of the Spectral
> scale (orange/yellow area) instead of starting at the '0' scale value (red
> area), and then continue until the 0.8 value area (green)...in essence, Id
> like to do a 'slice' of a given colormap, using BoundaryNorm or some other
> function, and using my levels array in order to break up the colormap.
> 
> What would be the best way to get this done?
> Can it be easily done using existing functions, or would I need to create my
> own colormap?

One way is to extract the colors you want from spectral, and use them 
with a boundary norm.  Suppose you want 10 colors because you have 11 
boundaries, and suppose they are in the range from 20 to 30:


import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm


boundaries = np.linspace(20, 30, 11)
colors = cm.spectral(np.linspace(0.3, 0.8, 10))
cmap = mcolors.ListedColormap(colors)
norm = mcolors.BoundaryNorm(boundaries, cmap.N)

z = 20 + np.random.rand(10,20)*10
plt.imshow(z, cmap=cmap, norm=norm)
plt.colorbar()
plt.show()

So yes, you are creating your own colormap, but it is easy.

Eric

> 
> Please help,
> 
> Thanks,
> P.Romero
> 
> 
> --
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
> trial. Simplify your report design, integration and deployment - and focus on 
> what you do best, core application coding. Discover what's new with 
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users