Re: [Matplotlib-users] Labeling/distinguishing lots of curves on a single plot

2010-08-23 Thread Chloe Lewis

And if you have mutually prime numbers of colors,
 linestyles, widths, you can automatically generate
more distinct lines than I can distinguish... If there's any
wxcuse for treating them as a series, I replot
when I know how many I have, and space the
colors through a colorbar.


&C
Away from home, checking mail rarely.

On Aug 23, 2010, at 2:11 PM, John Salvatier  
 wrote:


By the way, I found that the following generator expression made  
things easy:


def styles():
return ( {'c' : color, 'ls' : style, 'lw' : width} for color,  
style, width in itertools.product(colors, linestyles, linewidths))


then you can do something like

for result, style in zip(results, styles()):
pylab.plot(result[i], **style)

On Mon, Aug 23, 2010 at 1:22 PM, John Salvatier > wrote:

Thanks!


On Mon, Aug 23, 2010 at 12:38 PM, Aman Thakral  
 wrote:

Hi John,

Here is a simple way to do it.

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)

colors = ('red','green','blue','yellow','orange')
linestyles = ('-','--',':')
linewidths = (0.5,2)

y = np.random.randn(100,30)
x = range(y.shape[0])
i = 0

for c in colors:
for ls in linestyles:
for lw in linewidths:
ax.plot(x,y[:,i],c=c,ls=ls,lw=lw)
i+=1
plt.show()



On 10-08-23 03:06 PM, John Salvatier wrote:

Hello,

I have a plot with lots of curves on it (say 30), and I would like  
to have some way of distinguishing the curves from each other. Just  
plotting them works well for a few curves because they come out as  
different colors unless you specify otherwise, but if you do too  
many you start getting repeats is there a way to have matplotlib  
also vary the line style that it automatically assigns? Or perhaps  
someone has another way of distinguishing lots of curves?


Best Regards,
John


--- 
--- 
--- 
-

Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook  
users
worldwide. Take advantage of special opportunities to increase  
revenue and

speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users





--- 
--- 
--- 
-

Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook  
users
worldwide. Take advantage of special opportunities to increase  
revenue and

speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] a question about backend, matplotlib and ipython

2010-08-23 Thread Benjamin Root
On Mon, Aug 23, 2010 at 1:53 PM, xiaoni  wrote:

> Hello,
>  I got a problem with backend in matplotlib.
>  I used ipython for launching the codes and the backend of matplotlib
> is GTKAgg.   I have a code.py with a for loop for processing data, and in
> each iteration I read and plot and save the figures. Because there are so
> many figures, I set the non-interative mode and not using "show()" in the
> code. Then the memory is used more and more as the iteration number
> increases, and the most memory is due to write_png function. I guess that
> the figures (though not shown on the screen) from each iteration take the
> memory, and try to close the figures produced at each iteration.
> what I did:
> modify the backend to Agg in the code
> add "close('all')" before each iteration finish.
>
>This works for removing the memory problem. But a new issue arrive.
> After the run is finished, the ipython command window has no response to any
> keyboard input for a few seconds, then a warning message appear:
>"Warning: Timeout for mainloop thread exceeded switching to nonthreaded
> mode (until mainloop wakes up again)",
> and when I tried to quit ipython afterwards, it is stuck there and the
> ipython is crashed.
>But if I tried using "python code.py" , then it works well : no
> warnings.
>Does it mean that we can not use ipython and a backend non-GUI at the
> same time ?
>
>Any one would like to explain a bit ? Thanks in advance !!
>
>
> xiaoni
>
>
>
xiaoni,

For the way that you appear to be using ipython, it might be better to just
use regular python instead.  ipython is very useful for interactive systems
and other advanced topics, but for a simple, loop-driven image generator,
python will work just fine.

As for your memory usage, doing a clf() should be helpful to keep it under
control.  I should also note that ipython have been known to cause memory
use to grow due to the extra references it holds to the figure data,
although I don't know if this is still true in the latest version that is
currently being worked on.

I hope this helps,
Ben Root
--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Labeling/distinguishing lots of curves on a single plot

2010-08-23 Thread John Salvatier
By the way, I found that the following generator expression made things
easy:

def styles():
return ( {'c' : color, 'ls' : style, 'lw' : width} for color, style,
width in itertools.product(colors, linestyles, linewidths))

then you can do something like

for result, style in zip(results, styles()):
pylab.plot(result[i], **style)

On Mon, Aug 23, 2010 at 1:22 PM, John Salvatier
wrote:

> Thanks!
>
>
> On Mon, Aug 23, 2010 at 12:38 PM, Aman Thakral wrote:
>
>>  Hi John,
>>
>> Here is a simple way to do it.
>>
>> import matplotlib.pyplot as plt
>> import numpy as np
>> fig = plt.figure()
>> ax = fig.add_subplot(111)
>>
>> colors = ('red','green','blue','yellow','orange')
>> linestyles = ('-','--',':')
>> linewidths = (0.5,2)
>>
>> y = np.random.randn(100,30)
>> x = range(y.shape[0])
>> i = 0
>>
>> for c in colors:
>> for ls in linestyles:
>> for lw in linewidths:
>> ax.plot(x,y[:,i],c=c,ls=ls,lw=lw)
>> i+=1
>> plt.show()
>>
>>
>>
>> On 10-08-23 03:06 PM, John Salvatier wrote:
>>
>> Hello,
>>
>> I have a plot with lots of curves on it (say 30), and I would like to have
>> some way of distinguishing the curves from each other. Just plotting them
>> works well for a few curves because they come out as different colors unless
>> you specify otherwise, but if you do too many you start getting repeats is
>> there a way to have matplotlib also vary the line style that it
>> automatically assigns? Or perhaps someone has another way of distinguishing
>> lots of curves?
>>
>> Best Regards,
>> John
>>
>>
>> --
>> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
>> Be part of this innovative community and reach millions of netbook users
>> worldwide. Take advantage of special opportunities to increase revenue and
>> speed time-to-market. Join now, and jumpstart your future.
>> http://p.sf.net/sfu/intel-atom-d2d
>>
>>
>> ___
>> Matplotlib-users mailing 
>> listmatplotlib-us...@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>>
>
--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Labeling/distinguishing lots of curves on a single plot

2010-08-23 Thread John Salvatier
Thanks!

On Mon, Aug 23, 2010 at 12:38 PM, Aman Thakral wrote:

>  Hi John,
>
> Here is a simple way to do it.
>
> import matplotlib.pyplot as plt
> import numpy as np
> fig = plt.figure()
> ax = fig.add_subplot(111)
>
> colors = ('red','green','blue','yellow','orange')
> linestyles = ('-','--',':')
> linewidths = (0.5,2)
>
> y = np.random.randn(100,30)
> x = range(y.shape[0])
> i = 0
>
> for c in colors:
> for ls in linestyles:
> for lw in linewidths:
> ax.plot(x,y[:,i],c=c,ls=ls,lw=lw)
> i+=1
> plt.show()
>
>
>
> On 10-08-23 03:06 PM, John Salvatier wrote:
>
> Hello,
>
> I have a plot with lots of curves on it (say 30), and I would like to have
> some way of distinguishing the curves from each other. Just plotting them
> works well for a few curves because they come out as different colors unless
> you specify otherwise, but if you do too many you start getting repeats is
> there a way to have matplotlib also vary the line style that it
> automatically assigns? Or perhaps someone has another way of distinguishing
> lots of curves?
>
> Best Regards,
> John
>
>
> --
> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
> Be part of this innovative community and reach millions of netbook users
> worldwide. Take advantage of special opportunities to increase revenue and
> speed time-to-market. Join now, and jumpstart your future.
> http://p.sf.net/sfu/intel-atom-d2d
>
>
> ___
> Matplotlib-users mailing 
> listmatplotlib-us...@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Labeling/distinguishing lots of curves on a single plot

2010-08-23 Thread Aman Thakral

Hi John,

Here is a simple way to do it.

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)

colors = ('red','green','blue','yellow','orange')
linestyles = ('-','--',':')
linewidths = (0.5,2)

y = np.random.randn(100,30)
x = range(y.shape[0])
i = 0

for c in colors:
for ls in linestyles:
for lw in linewidths:
ax.plot(x,y[:,i],c=c,ls=ls,lw=lw)
i+=1
plt.show()


On 10-08-23 03:06 PM, John Salvatier wrote:

Hello,

I have a plot with lots of curves on it (say 30), and I would like to 
have some way of distinguishing the curves from each other. Just 
plotting them works well for a few curves because they come out as 
different colors unless you specify otherwise, but if you do too many 
you start getting repeats is there a way to have matplotlib also vary 
the line style that it automatically assigns? Or perhaps someone has 
another way of distinguishing lots of curves?


Best Regards,
John


--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d


___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
   


--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Colorbar labeling

2010-08-23 Thread Friedrich Romstedt
2010/8/20 Bruce Ford :
> I have a grid with values ranging from exactly 0.0 and 100.0.  When I
> plot this with colorbar, the base of the colorbar is labeled "-0.0".
> Is this a default for 0.0...to plot it with as a negative number?  Any
> workarounds?

How sure are you that the floating point number underneath has really
not set the negative bit?

Maybe try to .clip() the grid positions before on the numpy level to
(0.0, \infty) where 0 arises from a fresh parse of '0.0' by the
interpreter, i.e., a "really really zero" fp number.

To clip, you may also use

grid *= (grid > 0)

or similar things of that fashion.

I'm not sure if the mistake is implied my your side of the code, but i
just hope this helps maybe.  The Locator stuff is not soo easy.

Friedrich

--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Labeling/distinguishing lots of curves on a single plot

2010-08-23 Thread Justin McCann
Here are a couple of functions you might try, with a few colors and line
styles I use:


import itertools
from pylab import *

COLORS = ['#990033', '#FF', '#00FF00', '#F79E00',
  '#ff00ff', '#0080FF', '#FF', '#2D0668',
  '#2EB42E', '#ff6633', '#8000ff', '#33',
  '#cc0077', '#099499', '#996633', '#00']

def new_stylecolor_iter():
## Use these to alternate markers, or use all the styles.
## Combine them into the call to 'itertools.product' and
## then add the appropriate kwargs to the call to 'plot'
#markers = itertools.cycle(lines.Line2D.markers.keys())
#styles = itertools.cycle(lines.Line2D.lineStyles.keys())
## alternate colors first, line styles second
sc = itertools.product(['-', ':', '--', '-.'], COLORS)
return sc

def line_plot_alternate():
sc = new_stylecolor_iter()
for i in xrange(0,40):
style, color = sc.next()
plot(xrange(0,20), randn(20), label=str(i), linewidth=3,
linestyle=style, color=color)
legend()

if __name__ == "__main__":
line_plot_alternate()
show()




On Mon, Aug 23, 2010 at 3:06 PM, John Salvatier
wrote:

> Hello,
>
> I have a plot with lots of curves on it (say 30), and I would like to have
> some way of distinguishing the curves from each other. Just plotting them
> works well for a few curves because they come out as different colors unless
> you specify otherwise, but if you do too many you start getting repeats is
> there a way to have matplotlib also vary the line style that it
> automatically assigns? Or perhaps someone has another way of distinguishing
> lots of curves?
>
> Best Regards,
> John
>
>
>
> --
> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
> Be part of this innovative community and reach millions of netbook users
> worldwide. Take advantage of special opportunities to increase revenue and
> speed time-to-market. Join now, and jumpstart your future.
> http://p.sf.net/sfu/intel-atom-d2d
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plotting open symbols

2010-08-23 Thread Friedrich Romstedt
2010/8/20 Benjamin Root :
> This used to trip me up as well.  However, for colors in matplotlib, None
> (without quotes) tells mpl to use the default color, while 'None' (typically
> not case-sensitive) means "do not plot any color".

More precise, the string 'None' translates to fully transparent black,
as far as I understand.  The ps backend e.g. ignores such objects when
printing out then.

Freidrich

--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] polar plot

2010-08-23 Thread Friedrich Romstedt
2010/8/20 Michael Droettboom :
>> Yeah, it's my issue, but I'm not happy with fixing it.  Currently,
>> matplotlib forces the xticks (i.e., the theta ticks) to be at sensible
>> values via .set_xticks() and .set_xlabels() (projections/polar.py).
>>
>> I'm coding a matplotlib extension package which has to clear the axes
>> often, but restoring the major locators, the title and stuff after
>> clearing.  It was agnostic to the specialities of polar axes so far.
>
> Why and how are you restoring the major locator?  It seems like that's the
> issue.  I don't think preventing the theta locator from being changed is
> something we want to do.  Polar plots (by default) just set fixed theta
> ticks at multiples of pi/4.

My package provides support for Layers in matplotlib.  And the layers'
data can be changed, making a complete redraw of the axes a solution
much easier to implement than dealing with the fuzzy API stuff
directly.  I don't need high-performance.

When putting axes.clear(), the locator is being reset. In cartesian
coords, it happens that I want a MaxNLocator(nbins=3) or similiar from
time to time, and this must be restored then.  For cartesian axes, if
the user does not specify another locator, I'm setting the
AutoLocator(), what is the same what the (cartesian) axes does.
Dealing with the case "no locator set" (by "using matplotlib default
fallback") is neither nice nor straightforward.  (It has to do with
complicating the calling conventions.  I would have to treat the case
'ignore [x|y]locator' specially.)

It would maybe be a good solution to provide some abstract
Axes.get_default_locators(), being public.  Each SomeClass(Axes) can
define what they understand under "default locator".

>> I would rather suggest to insert a new Locator class being aware of
>> radians.  It would suffice to return tick positions dividing 2 pi into
>> an integer number of bins.  It's not necessary to cover all the
>> peculiarities of the old historic division system into 360 parts.
>
> Perhaps using FixedLocator, rather than explicitly setting the ticks using
> set_xticks (as polar plots currently do) would be better.  However, the
> locator could still be changed, not really addressing your problem.

Seems that you misunderstood my problem, if I'm not misunderstanding
you :-)  I have no problem with a "mutable" locator.  (But the user
has normally no access to the axes, only the Stack class changes the
axes.)

But right, I wanted to derive it from the Locator class framework,
just specialising the location.

> For convenience, however, we could add a locator that given n, divides 2pi
> into n parts.

Yes, and Ben's idea is quite nice, to make this accessible also to
rectangular plots.  This implies some simple thoughts on the view lims
to take them into account when issuing the tick locations.

>> Accompanying would be formatters in radians and degrees with
>> adjustable precision (no autodetect necessary).
>
> Sure.  Adding a radian formatter makes sense.

If we go into details let's switch to -devel maybe?

Friedrich

--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Labeling/distinguishing lots of curves on a single plot

2010-08-23 Thread John Salvatier
Hello,

I have a plot with lots of curves on it (say 30), and I would like to have
some way of distinguishing the curves from each other. Just plotting them
works well for a few curves because they come out as different colors unless
you specify otherwise, but if you do too many you start getting repeats is
there a way to have matplotlib also vary the line style that it
automatically assigns? Or perhaps someone has another way of distinguishing
lots of curves?

Best Regards,
John
--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] a question about backend, matplotlib and ipython

2010-08-23 Thread xiaoni
Hello,   
 I got a problem with backend in matplotlib.
 I used ipython for launching the codes and   the backend of 
matplotlib is GTKAgg.   I have a code.py with a for loop for processing data, 
and in each   iteration I read and plot and save the figures. Because 
there   are so many figures, I set the non-interative mode and not 
using 
"show()" in the code. Then the memory is used more and more as the   
iteration number increases, and the most memory is   due to write_png 
function. I guess that  the figures   (though not shown on the screen) 
from each iteration take the memory, and try to close the figures produced at 
each   iteration.
what I did:
modify the backend to Agg in the code
add "close('all')" before each iteration finish.

   This works for removing the memory problem. But a new issue   
arrive. 
After the run is finished, the ipython command window   has no response 
to any keyboard input for a few seconds, then a warning message appear:
   "Warning: Timeout for mainloop thread exceeded switching to   
nonthreaded mode (until mainloop wakes up again)",
and when I tried to quit ipython afterwards, it is stuck there   and 
the 
ipython is crashed.
   But if I tried using "python code.py" , then it works well : no warnings. 
   Does it mean that we can not use ipython and a backend non-GUI at the same 
time ?

   Any one would like to explain a bit ? Thanks in advance !!


xiaoni


  --
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Mapping fonts properly

2010-08-23 Thread Michael Droettboom

On 08/23/2010 11:08 AM, Daniel Hyams wrote:

Thanks for your response Michael!

Deleting the fontList.cache indeed solved the problem.  The first 
sample that I gave below now works fine under both Windows and Linux; 
whew...I would have never known about that cache file without your help.


So, should the fontList.cache file be deleted each time my app runs, 
in case new fonts have been installed since the last invocation?  How 
do we keep that cache up to date?
The cache exists because it can take a long time to read through all of 
the font files on the system each time matplotlib is imported.  It might 
be fast enough to simply stat the dates on all the files in the font 
directories (without reading their contents)... I don't know if 
experiments were done on this when the cache was originally added (that 
pre-dates me).


Mike



On Mon, Aug 23, 2010 at 10:12 AM, Michael Droettboom > wrote:


On 08/22/2010 10:00 PM, Daniel Hyams wrote:

I am searching for advice on how to handle selecting a specific
font, and using that in a matplotlib figure.  As a background,
the font will be picked through the wx.FontDialog (common font
dialog) provided by wxPython.  So, what I will have is the font
face (Arial, Times New Roman, Algerian, etc. etc.), the weight,
the style (italic, normal) and the point size.  All I want to do
is create a matplotlib font that matches this, and use it in the
plot.  My first try was this:

import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

# this does not work.  The title font is wrong.
the_font = 'Century Schoolbook'
fp = fm.FontProperties()
fp.set_name(the_font)
fp.set_size(24)
plt.title('The Title that should be in Century
Schoolbook',fontproperties=fp)
print fp
plt.show()

But that didn't work.  I know that "Century Schoolbook" is not
really a font family, but in the docs it says that you can list a
font there.

On my RHEL5 system (at least), the full name of that font is
"Century Schoolbook L".  You do, of course, have to match the font
name exactly.

You may want to experiment with using wx.Font.GetFaceName vs.
wx.Font.GetFamilyString from the font chooser dialog and see if
either returns the correct result.

You can see the list of fonts that matplotlib found on your system
by doing:

from matplotlib import font_manager
font_manager.fontManager.ttflist

(This is not a public API -- but may help with debugging the issue
here).

Is the font you are hoping to match with in that list?

Another thing you may want to try is deleting matplotlib's font
cache, in case this font was installed after matplotlib was first
run on your system.  It is is in a file "fontList.cache" and lives
in the user data area (can't remember the exact location of this
on Windows off hand).



The following does work, if I manually set the TrueType file
explicitly:

fp = fm.FontProperties()
fp.set_file('c:\\Windows\Fonts\CENSCBK.TTF')
fp.set_size(24)
print fp
plt.title('The Title that is in Century
Schoolbook',fontproperties=fp)
plt.show()

So I guess the question ishow does one accomplish this,
portably?  I don't quite understand the ins and outs of fonts.


p.s.
I did take a stab at creating a mapping between the font names /
weights / styles like this:

all_fontfiles = fm.win32InstalledFonts()
allfonts = fm.createFontList(all_fontfiles)
fontdict = {}
for f in allfonts:
fontdict[(f.name ,f.style,f.weight)] = f.fname

And I think I can get this to work, because this maps me to a TTF
file for any name, style, and weight combination.  But this
seemed awfully hacky, and I don't know what problems I'll run
into on other platforms (obviously, I would have get
all_fontfiles above differently on each platform).  If this is
the only way to do it, I guess that's OK, but I thought that
surely there was a better way.

That's basically a stricter way of doing what the matplotlib code
already does.  The matplotlib lookup is actually smarter because
it handles approximate "nearest neighbor" matches.  I think the
problem is more likely one of the above (an inexact name match or
an out-of-date font cache).

Mike

-- 
Michael Droettboom

Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA



--
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net

https

Re: [Matplotlib-users] Mapping fonts properly

2010-08-23 Thread Daniel Hyams
Thanks for your response Michael!

Deleting the fontList.cache indeed solved the problem.  The first sample
that I gave below now works fine under both Windows and Linux; whew...I
would have never known about that cache file without your help.

So, should the fontList.cache file be deleted each time my app runs, in case
new fonts have been installed since the last invocation?  How do we keep
that cache up to date?



On Mon, Aug 23, 2010 at 10:12 AM, Michael Droettboom wrote:

>  On 08/22/2010 10:00 PM, Daniel Hyams wrote:
>
> I am searching for advice on how to handle selecting a specific font, and
> using that in a matplotlib figure.  As a background, the font will be picked
> through the wx.FontDialog (common font dialog) provided by wxPython.  So,
> what I will have is the font face (Arial, Times New Roman, Algerian, etc.
> etc.), the weight, the style (italic, normal) and the point size.  All I
> want to do is create a matplotlib font that matches this, and use it in the
> plot.  My first try was this:
>
> import matplotlib.pyplot as plt
> import matplotlib.font_manager as fm
>
> # this does not work.  The title font is wrong.
> the_font = 'Century Schoolbook'
> fp = fm.FontProperties()
> fp.set_name(the_font)
> fp.set_size(24)
> plt.title('The Title that should be in Century
> Schoolbook',fontproperties=fp)
> print fp
> plt.show()
>
> But that didn't work.  I know that "Century Schoolbook" is not really a
> font family, but in the docs it says that you can list a font there.
>
> On my RHEL5 system (at least), the full name of that font is "Century
> Schoolbook L".  You do, of course, have to match the font name exactly.
>
> You may want to experiment with using wx.Font.GetFaceName vs.
> wx.Font.GetFamilyString from the font chooser dialog and see if either
> returns the correct result.
>
> You can see the list of fonts that matplotlib found on your system by
> doing:
>
> from matplotlib import font_manager
> font_manager.fontManager.ttflist
>
> (This is not a public API -- but may help with debugging the issue here).
>
> Is the font you are hoping to match with in that list?
>
> Another thing you may want to try is deleting matplotlib's font cache, in
> case this font was installed after matplotlib was first run on your system.
> It is is in a file "fontList.cache" and lives in the user data area (can't
> remember the exact location of this on Windows off hand).
>
>
> The following does work, if I manually set the TrueType file explicitly:
>
> fp = fm.FontProperties()
> fp.set_file('c:\\Windows\Fonts\CENSCBK.TTF')
> fp.set_size(24)
> print fp
> plt.title('The Title that is in Century Schoolbook',fontproperties=fp)
> plt.show()
>
> So I guess the question ishow does one accomplish this, portably?  I
> don't quite understand the ins and outs of fonts.
>
>
> p.s.
> I did take a stab at creating a mapping between the font names / weights /
> styles like this:
>
> all_fontfiles = fm.win32InstalledFonts()
> allfonts = fm.createFontList(all_fontfiles)
> fontdict = {}
> for f in allfonts:
> fontdict[(f.name,f.style,f.weight)] = f.fname
>
> And I think I can get this to work, because this maps me to a TTF file for
> any name, style, and weight combination.  But this seemed awfully hacky, and
> I don't know what problems I'll run into on other platforms (obviously, I
> would have get all_fontfiles above differently on each platform).  If this
> is the only way to do it, I guess that's OK, but I thought that surely there
> was a better way.
>
> That's basically a stricter way of doing what the matplotlib code already
> does.  The matplotlib lookup is actually smarter because it handles
> approximate "nearest neighbor" matches.  I think the problem is more likely
> one of the above (an inexact name match or an out-of-date font cache).
>
> Mike
>
> --
> Michael Droettboom
> Science Software Branch
> Space Telescope Science Institute
> Baltimore, Maryland, USA
>
>
>
> --
> This SF.net email is sponsored by
>
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>


-- 
Daniel Hyams
dhy...@gmail.com
--
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev ___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Mapping fonts properly

2010-08-23 Thread Michael Droettboom

On 08/22/2010 10:00 PM, Daniel Hyams wrote:
I am searching for advice on how to handle selecting a specific font, 
and using that in a matplotlib figure.  As a background, the font will 
be picked through the wx.FontDialog (common font dialog) provided by 
wxPython.  So, what I will have is the font face (Arial, Times New 
Roman, Algerian, etc. etc.), the weight, the style (italic, normal) 
and the point size.  All I want to do is create a matplotlib font that 
matches this, and use it in the plot.  My first try was this:


import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

# this does not work.  The title font is wrong.
the_font = 'Century Schoolbook'
fp = fm.FontProperties()
fp.set_name(the_font)
fp.set_size(24)
plt.title('The Title that should be in Century 
Schoolbook',fontproperties=fp)

print fp
plt.show()

But that didn't work.  I know that "Century Schoolbook" is not really 
a font family, but in the docs it says that you can list a font there.
On my RHEL5 system (at least), the full name of that font is "Century 
Schoolbook L".  You do, of course, have to match the font name exactly.


You may want to experiment with using wx.Font.GetFaceName vs. 
wx.Font.GetFamilyString from the font chooser dialog and see if either 
returns the correct result.


You can see the list of fonts that matplotlib found on your system by doing:

from matplotlib import font_manager
font_manager.fontManager.ttflist

(This is not a public API -- but may help with debugging the issue here).

Is the font you are hoping to match with in that list?

Another thing you may want to try is deleting matplotlib's font cache, 
in case this font was installed after matplotlib was first run on your 
system.  It is is in a file "fontList.cache" and lives in the user data 
area (can't remember the exact location of this on Windows off hand).


The following does work, if I manually set the TrueType file explicitly:

fp = fm.FontProperties()
fp.set_file('c:\\Windows\Fonts\CENSCBK.TTF')
fp.set_size(24)
print fp
plt.title('The Title that is in Century Schoolbook',fontproperties=fp)
plt.show()

So I guess the question ishow does one accomplish this, portably?  
I don't quite understand the ins and outs of fonts.



p.s.
I did take a stab at creating a mapping between the font names / 
weights / styles like this:


all_fontfiles = fm.win32InstalledFonts()
allfonts = fm.createFontList(all_fontfiles)
fontdict = {}
for f in allfonts:
fontdict[(f.name ,f.style,f.weight)] = f.fname

And I think I can get this to work, because this maps me to a TTF file 
for any name, style, and weight combination.  But this seemed awfully 
hacky, and I don't know what problems I'll run into on other platforms 
(obviously, I would have get all_fontfiles above differently on each 
platform).  If this is the only way to do it, I guess that's OK, but I 
thought that surely there was a better way.
That's basically a stricter way of doing what the matplotlib code 
already does.  The matplotlib lookup is actually smarter because it 
handles approximate "nearest neighbor" matches.  I think the problem is 
more likely one of the above (an inexact name match or an out-of-date 
font cache).


Mike

--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

--
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev ___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Animated artists not present in savefigged files

2010-08-23 Thread Daπid
What I use to create animations is plainly:

savefig(head+str(filecode).zfill(digits)+format, dpi=205)
plt.clf()
filecode+=1

where filecode is the name, digits an int and format usually .png.

clf() is important in order to prevent memory leaks, because otherwise
mpl stores all the figures one in top of the other, consuming a lot of
resources once you have a several images.

To stick all of them together, I use a video editor.


On Mon, Aug 23, 2010 at 2:59 PM, Kim Hansen  wrote:
> Hi list,
>
> I am using animated artists to generate an animation, where I save each step
> in the anmantion as a png using the savefig method of the figure instance
> after drawing the animated artists on a cached background and after
> fig.canvas.blit.
>
> What I see on screen are the updated animated artists being drawn, but only
> the cached background with subplots and axes and grid is being stored in the
> savefig commands
> called after the last blit.
>
> Why is only the background saved.?
>
> I am using matplotlib ver. 0.99.1 and the 'TkAgg' backend on a Win XP PC.
>
> Thanks in advance,
> Kim
> --
> This SF.net email is sponsored by
>
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>

--
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Animated artists not present in savefigged files

2010-08-23 Thread John Hunter
On Mon, Aug 23, 2010 at 7:59 AM, Kim Hansen  wrote:
> Hi list,
>
> I am using animated artists to generate an animation, where I save each step
> in the anmantion as a png using the savefig method of the figure instance
> after drawing the animated artists on a cached background and after
> fig.canvas.blit.
>
> What I see on screen are the updated animated artists being drawn, but only
> the cached background with subplots and axes and grid is being stored in the
> savefig commands
> called after the last blit.
>
> Why is only the background saved.?

The animated property tells the figure to not draw the artist on a
call to figure.draw, which is wha savefig calls.  This enables you to
draw the background (everything but the animated artists) with a call
to figure.canvas.draw, and then selectively draw your animated artists
when you want.  It does pose a problem for saving.

The best approach is to turn off the animated property right before
saving, and turn it back on as needed.  Something like

artists = fig.get_children()

animated = dict()
for artist in artists:
animated[artist] = artist.get_animated()
artist.set_animated(False)

fig.savefig('myfig.png')

for artist in artists:
artist.set_animated(animated[artist])

Also, Ryan May has been working on a nice framework for animation that may help,

http://github.com/dopplershift/Animation

JDH

--
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Animated artists not present in savefigged files

2010-08-23 Thread Kim Hansen
Hi list,

I am using animated artists to generate an animation, where I save each step
in the anmantion as a png using the savefig method of the figure instance
after drawing the animated artists on a cached background and after
fig.canvas.blit.

What I see on screen are the updated animated artists being drawn, but only
the cached background with subplots and axes and grid is being stored in the
savefig commands
called after the last blit.

Why is only the background saved.?

I am using matplotlib ver. 0.99.1 and the 'TkAgg' backend on a Win XP PC.

Thanks in advance,
Kim
--
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev ___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users