Re: [Matplotlib-users] plotting an array of enumerated values

2006-06-16 Thread John Pye
By the way, I had some success with this, but my approach is really
inefficient. Perhaps someone could suggest how I can improve the following:

import matplotlib.numerix as nx
from numarray import ma

def enumimage(A,colors):

Create an image from a matrix of enumerated values
A is a matrix
colors is a dictionary mapping enumerated values to (r,g,b,a) tuples
If a value in A is masked, the resulting image will be transparent
If a value in A is not present in the color map, it will plot black.


B = nx.zeros((nx.size(A,0),nx.size(A,1),4))
mask = A.mask()

for r in range(nx.size(A,0)):
for c in range(nx.size(A,1)):
v = A[r,c]
if mask[r,c]:
B[r,c,:]=[1,1,1,0]
else:
try:
B[r,c,:]=colors[v]
except KeyError,e:
B[r,c,:]=[0,0,0,1]

return B
   
if __name__=='__main__':
import pylab
A = nx.array([[1,2,7],[1,2,2],[1,1,9]])
print A =,A
A1 = ma.array(A,mask=ma.where(A==1,1,0))   
print A1 =,A1
colors={
2:(1,0,0,1)
,7:(0,1,0,1)
}
B = enumimage(A1,colors)
print B =,B
pylab.figure()
pylab.hold()
   
pylab.imshow(B,interpolation='nearest',extent=0.5+nx.array([0,nx.size(A,0),nx.size(A,1),0]))
pylab.axes
pylab.show()


John Pye wrote:
 Hi all

 I have some data with enumerated values in an array. Values are like
 1,2,7,9 spread around in the array. I want to plot those values so that
 I can see the 'regions' in my data, then I want to overlay this with
 some contour lines drawn from other data.

 I want to be able to specify the colors for each of the enumerated
 values, as they need to be consistent throughout my work. My array of
 enumerated values is *masked* so that there are areas where I don't want
 to show anything (this would plot as transparent pixels).

 Has anyone got suggestions on the best way of doing this? It seems that
 the technique in
 http://www.scipy.org/Cookbook/Matplotlib/Plotting_Images_with_Special_Values
 might be overkill, right? It also seemed that it had some problems with
 masked arrays.

 Cheers

 JP

   

-- 
John Pye
School of Mechanical and Manufacturing Engineering
The University of New South Wales
Sydney  NSW 2052  Australia
t +61 2 9385 5127
f +61 2 9663 1222
mailto:john.pye_AT_student_DOT_unsw.edu.au
http://pye.dyndns.org/



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


Re: [Matplotlib-users] latex labels on plots

2006-06-16 Thread Wolfgang
Hi,

frac works for me:

yaxislabel=r'\sffamily water content $\left( 
\frac{\textsf{kg}}{\textsf{m}^{\textsf{\small 2}}}\right) $'

ylabel(yaxislabel)


And you can also set
rc('text', usetex=False)
in your file to enable or disable tex

in my case I did the following:

tex_out=True # False
if tex_out:
 xaxislabel=r'time ($\sqrt{\textsf{s}}$)'
 yaxislabel=r'\sffamily water content $\left( 
\frac{\textsf{kg}}{\textsf{m}^{\textsf{\small 2}}}\right) $'
 rc('text', usetex=True)
else:
 xaxislabel='time (s**0.5)'
 yaxislabel='water content (kg/m2)'
 rc('text', usetex=False)

It's perhaps not the mose elegant way to do, but I'm quite new to 
python/pylab/matplotlib


Wolfgang

John Pye schrieb:
 Hi all
 
 I came across this page: http://www.scipy.org/Cookbook/Matplotlib/UsingTex
 which mentions using LaTeX to generate labels on plots in Matplotlib.
 
 What I only discovered recently is that you don't need this 'usetext=1'
 thing in order to create captions on plots that include subscripts, etc.
 According to section 2.6.4 of the user's guide, you can just surround
 your text with $...$ to have it formatted as if it were latex. This is
 especially important if you're exporting SVG graphics (eg if you want to
 add more captioning/labelling using inkscape): the 'usetex' approach
 fails in that case.
 
 I wonder if someone with write access to the scipy wiki could maybe
 update the above page with some comments about the 'mathtext' support in
 Matplotlib? It might also be worth noting that the mathtext
 functionality doesn't support the \frac operator.
 
 Cheers
 JP
 



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


Re: [Matplotlib-users] exponent fonts with usetex

2006-06-16 Thread Ryan Krauss
It seems like no one has any comments on our plans concerning the
exponent fonts.  Can you outline for me what it would take to fix
this?  If it is fairly simple I may take a crack at it.

Ryan

On 6/14/06, Darren Dale [EMAIL PROTECTED] wrote:
 I agree that this little experiment of trying to work around latex's
 limitations has been too much trouble. I suggest we go back to the old
 behavior, and anyone who wants sans-serif fonts in their exponents can use
 regular mathtext. I'm hopeful that Edin can make some strides with mpl's
 mathtext support, and in the meantime, people should get decent results if
 they set ps.useafm : True in their rc settings.

 Comments?


 On Wednesday 14 June 2006 19:53, Ryan Krauss wrote:
  (Sorry, I submitted this email with a real figure instead of a toy
  example and the file size  was too big and it awaits moderator
  approval).
 
  I am afraid I asked you to open a can of worms and now I don't know
  what we should do.  With my font size settings, \small looks to small
  for the exponents.  I tried \normalsize and actually got decent
  results with \large (replacing all occurances of \small in your
  ticker.py).  See that attached file.  But if \small looked good with
  your settings, I am afraid things are now dependent on the font
  settings in the rc file as far as what should go in the latex command
  for the exponents.
 
  I remember that this problem came up because I complained about serif
  fonts in my exponents and we were having a hard time making tex use
  sans serif math fonts.
 
  Maybe the best solution is for me to go back in time and retract that
  complaint.
 
  I don't know.  Sorry about the mess this had made.  I have plots I am
  fairly happy with (I will poke around in my rc file and see if I can
  find out why my x and y axis fonts look different).
 
  Ryan
 
  On 6/14/06, Ryan Krauss [EMAIL PROTECTED] wrote:
   I am afraid I asked you to open a can of worms and now I don't know
   what we should do.  With my font size settings, \small looks to small
   for the exponents.  I tried \normalsize and actually got decent
   results with \large (replacing all occurances of \small in your
   ticker.py).  See that attached file.  But if \small looked good with
   your settings, I am afraid things are now dependent on the font
   settings in the rc file as far as what should go in the latex command
   for the exponents.
  
   I remember that this problem came up because I complained about serif
   fonts in my exponents and we were having a hard time making tex use
   sans serif math fonts.
  
   Maybe the best solution is for me to go back in time and retract that
   complaint.
  
   I don't know.  Sorry about the mess this had made.  I have plots I am
   fairly happy with (I will poke around in my rc file and see if I can
   find out why my x and y axis fonts look different).
  
   Ryan
  
   On 6/14/06, Ryan Krauss [EMAIL PROTECTED] wrote:
I feel bad that I caused this problem and am now asking you to fix it.
   
Ryan
   
On 6/14/06, Darren Dale [EMAIL PROTECTED] wrote:
 This is an artifact that was introduced when I tried to give you
 support for sans-serif fonts in the exponent. Try the attached
 ticker.py, it wraps the exponent in {\small}. Let me know if this is
 acceptable, and I'll commit it.

 On Wednesday 14 June 2006 19:14, Ryan Krauss wrote:
  I still have the problem with large exponents with your
  matplotlibrc file (but the y-axis plots are no longer different).
 
  Any thoughts on what I should try next?
 
  Ryan
 
  On 6/14/06, Darren Dale [EMAIL PROTECTED] wrote:
   On Wednesday 14 June 2006 18:51, you wrote:
There was a lot of stuff in my tex.cache, but deleting didn't
solve my problem.
   
I may have some strange choices for my fonts and font sizes.
Can you send me a copy of your matplotlibrc file.
   
Ryan
   
On 6/14/06, Darren Dale [EMAIL PROTECTED] wrote:
 Hi Ryan,

 I'm using the latest svn as well (2479), and I cant reproduce
 your problem. Try deleting your tex.cache.

 Darren

 On Wednesday 14 June 2006 18:14, Ryan Krauss wrote:
  I am having a problem with the fonts for exponents on
  semilog plots with usetex.
 
  The attached figure can be generated on my machine with
  figure(1)
  t=arange(0,10,0.01)
  y=sin(2*pi*t)
  semilogx(t,y)
 
  I just upgraded to the latest svn and now the y-axis plots
  look different from the x-axis.
  matplotlib.__version__
  Out[6]: '0.87.3'
 
 
  Ryan

 --
 Darren S. Dale, Ph.D.
 Cornell High Energy Synchrotron Source
 Cornell University
 200L Wilson Lab
 Rt. 366  Pine Tree Road
 Ithaca, NY 14853