[Matplotlib-users] custom color cycle from cmap

2010-04-08 Thread KrishnaPribadi

Hi, 
I'm trying to plot a set of lines, 12 to be exact, and the default color
cycle only supports 8 or 9 distinct colors. That said, I looked up the color
maps and segmented it using 12 constant intervals with the hope of getting
12 distinct colors.

The problem I'm running in to is that some of the line colors I get are too
close to each other. This is because come shades in the colormap have a
broader spectrum than others.

Here is my code to set my custom default color cycle:

import matplotlib as mpl
cmap = mpl.cm.get_cmap(name='spectral') #I gues we can also use
hsv or gist_rainbow
nColors = 12 #number of colors
incr = 0.9 / nColors

self.mycolors = []
for i in np.arange(0,0.9,incr):
self.mycolors.append(cmap(i))

mpl.axes.set_default_color_cycle(self.mycolors)

Can anyone suggest a cleaner method? Or is there perhaps an existing class
to provide distinct color lines?

Thanks,
Krishna
-- 
View this message in context: 
http://old.nabble.com/custom-color-cycle-from-cmap-tp28177653p28177653.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap white space

2010-04-08 Thread Filipe Fernandes
Sorry, my bad. I always hit reply without checking... it is not the
first time did that,

Here is the solution for the list sake:

 trim image 
import StringIO, Image
imgdata = StringIO.StringIO()
fig.savefig(imgdata, dpi=300, format='png')
imgdata.seek(0)
im = Image.open(imgdata)

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)

im = trim(im,'white')
im.show()


The StringIO trick is a copy-and-paste from the matplotlib faq. And the
trim function I got from here:

http://mail.python.org/pipermail/image-sig/2008-July/005092.html


Thanks for the discussion, I learned a lot abouth the Agg backend.


BTW: What I meant by limitation is the fact that Agg has no GUI like the
nice QT window I was using before. The users of this script have no
experience with scripting languages and enjoyed choosing the format and
filename using a GUI interface.

In addition, PIL's show() use an external linux program xv. In the end
I wanted to eliminate one external linux program (Imagemagik convert)
but ended up with another one...

Best, Filipe

On 04/06/2010 05:01 PM, Friedrich Romstedt wrote:
 2010/4/5 Filipe Fernandes ocef...@gmail.com:
 Thanks a lot. In the end the StringIO-solution worked fine. The only
 limitation is that this works only for the Agg backend.
 [...]
 
 I'm happy to hear this.  As far as I know, using the Agg backend is
 not a limitation, because it provides fully anti-aliased output.
 Besides being available on all platforms (?).
 
 Let me make a small hint: The matplotlib-users mailing list is
 configured that by default replies go to the sender only, not to
 matplotlib-users, so maybe you want to let the list know about your
 solution?
 
 Anyway I'm happy for your Thanks,
 so thanks too,
 Friedrich

--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] custom color cycle from cmap

2010-04-08 Thread Tony S Yu

On Apr 8, 2010, at 8:13 AM, KrishnaPribadi wrote:

 
 Hi, 
 I'm trying to plot a set of lines, 12 to be exact, and the default color
 cycle only supports 8 or 9 distinct colors. That said, I looked up the color
 maps and segmented it using 12 constant intervals with the hope of getting
 12 distinct colors.
 
 The problem I'm running in to is that some of the line colors I get are too
 close to each other. This is because come shades in the colormap have a
 broader spectrum than others.
 
 Here is my code to set my custom default color cycle:
 
import matplotlib as mpl
cmap = mpl.cm.get_cmap(name='spectral') #I gues we can also use
 hsv or gist_rainbow
nColors = 12 #number of colors
incr = 0.9 / nColors
 
self.mycolors = []
for i in np.arange(0,0.9,incr):
self.mycolors.append(cmap(i))

you could replace the loop with a list comprehension:

 mycolors = [cmap(i) for i in np.arange(0,0.9,incr)]

Also, arange may not be a great fit for this task; maybe linspace would work 
better:

 mycolors = [cmap(i) for i in np.linspace(0, 0.9, nColors)]

This allows you to eliminate the assignment of `incr`. Note: the above colormap 
is different than that created by arange because linspace includes the 
endpoint, while arange doesn't.

Hope that helps,
-Tony

 
mpl.axes.set_default_color_cycle(self.mycolors)
 
 Can anyone suggest a cleaner method? Or is there perhaps an existing class
 to provide distinct color lines?
 
 Thanks,
 Krishna

--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap white space

2010-04-08 Thread Friedrich Romstedt
2010/4/8 Filipe Fernandes ocef...@gmail.com:
 BTW: What I meant by limitation is the fact that Agg has no GUI like the
 nice QT window I was using before. The users of this script have no
 experience with scripting languages and enjoyed choosing the format and
 filename using a GUI interface.

I'm quite convinced that you can have the figure in multiple Canvases
at the same time.  Or create the FigureCanvasAgg or the call to
.savefig() only on save time.  In every widget framework, it should be
fairly easy to build a custom gui having a customised Save ...
button, I guess?

 In addition, PIL's show() use an external linux program xv. In the end
 I wanted to eliminate one external linux program (Imagemagik convert)
 but ended up with another one...

When using Tkinter, you can use ImageTk:

im = {some PIL Image}  # Some image to be shown
canvas = {some Tkinter.Canvas}  # For drawing graphics

viewport = ImageTk.PhotoImage(im)

canvas.create_image((0, 0), image = viewport, anchor = 'nw')  # Put
the image on the Tkinter.Canvas.  Modify according your needs.

# Now the PIL Image has been rendered on the canvas.

# Maybe do canvas.update() or call the master's .update(),
# or call some .mainloop() entry function.  For instance, use the
# Tkinter.Tk instance's method .mainloop().

When renewing the graphics, don't forget to canvas.delete({tag}) using
the {tag} returned by canvas.create_image(), otherwise you will
probably loose perfomance.

There are examples on matplotlib.sourceforge.net how to use Tkinter
with matplotlib.

hth,
Friedrich

--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] custom color cycle from cmap

2010-04-08 Thread KrishnaPribadi

Thanks Tony. That helps clean up the code.

Now that I think about it more, I actaually had 2 questions.
The first you answered well.

The second question relates to my problem when using this method in that it
produces line colors where some colors are too similar. In other words,
there isn't enough of a stark differnece in color between the lines. Can
someone suggest a different method (or something that may already be built
in) of coming up with 12 or more line colors (more than the built in 8) that
are stark? (I know I'm nit-picking and can probably just pick out my own
colors but it's an interesting excersize).
-- 
View this message in context: 
http://old.nabble.com/custom-color-cycle-from-cmap-tp28177653p28180731.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] can't interact with embedded gtk

2010-04-08 Thread Mathew Yeates
The following works without the --pylab switch but not with it. The error I
get is some how related to a call to get the active figure  which returns
None.

C:\Python26\lib\site-packages\mpl_toolkits\basemap\__init__.pyc in
set_axes_limi
ts(self, ax)
   2531 if is_interactive():
   2532 figManager = _pylab_helpers.Gcf.get_active()
- 2533 figManager.canvas.draw()

AttributeError: 'NoneType' object has no attribute 'canvas'.

In the following code. the error happens at
m.drawcoastlines()

Help?

===
from mpl_toolkits.basemap import Basemap, shiftgrid
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_gtkagg import \
FigureCanvasGTKAgg as FigureCanvas
import gtk

# create new figure
#fig=plt.figure()
from matplotlib.figure import Figure
fig = Figure(figsize=(5,5), dpi=100)
canvas = FigureCanvas(fig)
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.add(canvas)
# setup cylindrical equidistant map projection (global domain).
ax = fig.add_axes([0.1,0.1,0.7,0.7])
m = Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\
resolution='c',area_thresh=1.,projection='cyl',ax=ax)
m.drawcoastlines()
m.tissot(-117,34,10,10)
#plt.show()
canvas.show()
window.show()
--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] 2 lines, 2 diff colors, when converged, gets 3rd color...

2010-04-08 Thread KrishnaPribadi

I'm plotting 2 lines with 2 colors. The lines are binary so they are somewhat
square. When the lines converge on a same value for a period, their colors
combine and turn into a 3rd color 

Is there a way to force the plotting to not blend the 2 colors together? I
just want the 2nd line to lay on top of the 1st line.

Any suggestions?
-- 
View this message in context: 
http://old.nabble.com/2-lines%2C-2-diff-colors%2C-when-converged%2C-gets-3rd-color...-tp28182679p28182679.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] 2 lines, 2 diff colors, when converged, gets 3rd color...

2010-04-08 Thread Michael Droettboom
The default behavior should be for the lines not to blend.  Can you 
provide a short example script that illustrates what you're seeing?  Or 
an image?

Mike

KrishnaPribadi wrote:
 I'm plotting 2 lines with 2 colors. The lines are binary so they are somewhat
 square. When the lines converge on a same value for a period, their colors
 combine and turn into a 3rd color 

 Is there a way to force the plotting to not blend the 2 colors together? I
 just want the 2nd line to lay on top of the 1st line.

 Any suggestions?
   

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA


--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] a quick way to plot 3D surface with point coordination?

2010-04-08 Thread ericyosho
Yes,
Thanks, Friedrich. :-)
This is exactly what I want. By now I know we have to plot over a
uniformly sampled plane any way at the end of the day, no matter
whether our original data is uniformly sampled or not.

Zhe Yao


On Thu, Apr 8, 2010 at 6:07 PM, Friedrich Romstedt
friedrichromst...@gmail.com wrote:
 2010/4/4 ericyosho ericyo...@gmail.com:
 Year, I think we could do unsorted scatter plot as well, however I'm
 still not satisfied with the book tracking routines I have to check
 when doing the surface plotting.

 What do you mean with book tracking routines?

 Anyway, maybe griddata would help you:
 http://matplotlib.sourceforge.net/api/mlab_api.html#matplotlib.mlab.griddata

 Friedrich


--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Colorbar shifting

2010-04-08 Thread Rachel-Mikel Arce Jaeger
Hello everyone,

I'm working with hexbin() and I'd like the output to be shifted towards the red 
end of the spectrum. Does anyone know if there's a way to shift how the colors 
are output?

Thanks!
Rachel

--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] getting legend loc

2010-04-08 Thread Peter Butterworth
Hi,

I'm having trouble getting some properties that are easily set :


leg=legend(loc=0)
is there a way to retrieve the legend location ?

In a similar vein :
axis('scaled')
is there a way to retrieve the scaled property ?

If no methods/properties are available in the default API is it
possible to implement them easily ?

--
Download Intel#174; 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users