Re: [Matplotlib-users] 1d heat map

2011-07-21 Thread Yoshi Rokuko
what are you using right now, something like that?

 a = np.random.random(70)
 x = np.empty([10,a.shape[0]])
 x[:,:] = a
 pl.contourf(x)

you might want to suppress ticks on the y-axis.

best regards, yoshi

--
5 Ways to Improve  Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] hot to draw a line connecting a list of points

2011-07-21 Thread robert rottermann
who ever migth be interested:
I achieved my goal in drawing lines trough a set of points using the path modul.

http://matplotlib.sourceforge.net/users/path_tutorial.html

robert
On 20.07.2011 20:49, robert rottermann wrote:
 hi there,

 I would like to draw a a set of lines on top of an image.
 Somehow I do not get the result I want

 these are the points ((267, 140), (380, 773), (267, 958))

 one of my divers atempts is:

 pic = plt.imread('../hlwd/effizienz_balken_01.jpg')
 pic = np.fliplr(np.rot90(pic, k=2))
 plt.imshow(pic)

 frame1 = plt.gca()

 lx = []
 ly = []
 for pt in ((267, 140), (380, 773), (267, 958)):
   lx.append(pt[0])
   ly.append(pt[1])
 x,y = np.array([lx, ly])
 line = mlines.Line2D(x, y, lw=5., alpha=0.4)

 frame1.add_line(line)

 plt.show()

 which produces on line instad of two.

 thanks for any pointers
 robert


 --
 10 Tips for Better Web Security
 Learn 10 ways to better secure your business today. Topics covered include:
 Web security, SSL, hacker attacks  Denial of Service (DoS), private keys,
 security Microsoft Exchange, secure Instant Messaging, and much more.
 http://www.accelacomm.com/jaw/sfnl/114/51426210/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
5 Ways to Improve  Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Some more mplot3d questions

2011-07-21 Thread Benjamin Root
On Thu, Jul 21, 2011 at 1:10 AM, gary ruben gary.ru...@gmail.com wrote:

 I'm trying to make a surface plot using the latest version of mplot3d
 from the git trunk and I have a couple of questions. The attached
 image is close to what I would like. The associated plot command I am
 using is

 ax.plot_surface(X, Y, Z, rstride=1, cstride=1, alpha=0.8, shade=True,
cmap=plt.cm.summer,
color='k',
facecolors='k',
lightsource = LightSource(azdeg=0, altdeg=0),
)

 1. Is there support now to automatically annotate the axis so that a
 multiplier is added, as occurs in 2D plots, or should I do this
 manually by rescaling the data for the moment?


Yes, offset text is now automatic and should activate in similar manner as
it does for regular 2D axis formatters.  You were one order of magnitude off
from automatically triggering it.  Also, I should note that it might be
better to use ax = fig.gca(projection='3d') instead of ax = Axes3D(fig)
because the former will leave more of a margin, which would allow the offset
text to be fully visible.  If you want the full figure area, then you may
need to fiddle with the ax.zaxis._axinfo['label']['space_factor'] to bring
it and the axis label closer to the axis.

The odd thing that I am encountering right now while investigating your
problem is that I can't seem to force the use of the offset.  It could just
be that I am doing it wrong, but I will look closer.


 2. Currently, it doesn't appear possible to shade the surface patches
 according to just a base facecolor and their orientation to a light
 source. Do I have to define a new colormap with a constant/single
 colour to achieve this?


Looking over the plot_surface code, this appears to be the case, however,
looking back over the LightSource code, I believe it might be possible to
update plot_surface to operate on situations where no cmap is specified.  I
will take a look today at that possibility and see if I can get it out for
the v1.1.0 release.


 3. I have set alpha=0.8 to allow the wireframe lines to show through a
 little. When shade=False, the wireframe is visible but I lose
 orientation-based shading. Is there a way to overlay the wireframe
 properly when shade=True?


In plot_surface, when shade=True, it appears that both the facecolors and
the edgecolors are set to the same colors.  The only reason why the lines
show up when you set transparency is that that alpha value is applied only
to the faces and not the edges.  Specifically, the logic is as follows:

if fcolors is specified, then set that color for both facecolor and
edgecolor.
Else, if a cmap is specified, then give the polygon collection the data,
limits and norm it needs to determine color itself.
Else, then use the value of color to specify only the facecolors.

I think the first branch of this logic is a bit wonky.  I am inclined to
make a small change that would only set the edgecolors if 'edgecolors' was
not provided as a kwarg.  This would enable users to specify the edgecolor
they want without worrying about something else over-riding it.  The only
problem seems to be that there would be no shading of these grid lines.
Would that still be acceptable to you?

Thanks for your valuable feedback!
Ben Root
--
5 Ways to Improve  Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] hot to draw a line connecting a list of points

2011-07-21 Thread Paul Ivanov
Hi Robert,

robert rottermann, on 2011-07-21 11:25,  wrote:
 who ever migth be interested:
 I achieved my goal in drawing lines trough a set of points using the path 
 modul.
 
 http://matplotlib.sourceforge.net/users/path_tutorial.html

Unless there were other considerations for getting this plot, it
really didn't have to be this complicated, read on.
 
 On 20.07.2011 20:49, robert rottermann wrote:
  frame1 = plt.gca()
  lx = []
  ly = []
  for pt in ((267, 140), (380, 773), (267, 958)):
lx.append(pt[0])
ly.append(pt[1])
  x,y = np.array([lx, ly])
  line = mlines.Line2D(x, y, lw=5., alpha=0.4)
  frame1.add_line(line)

The above can be done with just two lines:
x,y = zip(*((267, 140), (380, 773), (267, 958)))
1.plot(x,y)

best,
-- 
Paul Ivanov
314 address only used for lists,  off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 


signature.asc
Description: Digital signature
--
5 Ways to Improve  Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] PolyCollection and replotting

2011-07-21 Thread Fernando Moura
I am facing problems for plotting figures using polycollection. The
code below should do:

1- set two triangles: one with vertices at [0,0  0,1 1,0]  and the
other at [1,0 0,1 1,1]
2- give two random values to them
3- add these polygons to polycollection and set their values
4- plot the triangles edges only with triplot and save the eps
4.5- plot again with triplot and save the eps (I will explain why I am
doing this)
5- plot the image with the values (using add_collection) and save as eps
6- set two new random values to these triangles (this step is not
needed to reproduce the error)
7- plot again the image (using add_collection) and save as eps

Steps 1 to 6 seem to be ok. The problem is that on step 7, the
triangles are displaced in x and y directions. The graph is shown
correctly on screen, however this displacement appears on the output
file. This displacement does not appears when I plot twice the mesh
with triplot. Only when I plot using add_collection.

Thanks.

Fernando.


my settings are:


matplotlib version: 1.0.1
matplotlib obtained from: deb
http://ppa.launchpad.net/valavanisalex/matplotlib/ubuntu natty main
system: Linux kalman 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28
15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
no customizations on matplotlibrc

running python with --verbose-helpful option returns

$HOME=/home/fernando
CONFIGDIR=/home/fernando/.matplotlib
matplotlib data path /usr/share/matplotlib/mpl-data
loaded rc file /etc/matplotlibrc
matplotlib version 1.0.1
verbose.level helpful
interactive is False
units is False
platform is linux2
Using fontManager instance from /home/fernando/.matplotlib/fontList.cache
backend TkAgg version 8.5
findfont: Matching
:family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=medium
to DejaVu Sans (/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf)
with score of 0.10


#---
# CODE - CODE - CODE
#---

# -*- coding: utf-8 -*-

import os
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.tri as tri
from matplotlib.collections import PolyCollection
import numpy as np

class triangles_mesh():
def __init__(self,coords,topology,colormap=cm.gray):
values=np.random.rand(topology.shape[0])
self.triangles=self.build_triangles(coords,topology,values,colormap)

def build_triangles(self,coords,topology,image_rho,map_colors=cm.jet):
(n_elem,n_nodes_local)=topology.shape
lista_tri=[]
colors=[]
values_rho=[]
for j in range(0,n_elem):
verts = [(coords[i,0], coords[i,1]) for i in topology[j,:]]
lista_tri.append(verts)
values_rho.append(image_rho[j])

norma = cm.colors.Normalize(vmin=0, vmax=3)

poligonos = PolyCollection(lista_tri,lw=0.4,cmap=map_colors,norm=norma)
poligonos.set_array(np.array(values_rho))
return poligonos

class mesh_2D():
def __init__(self):
self.topology=np.array([[0,1,2],[1,3,2]])
self.coords=np.array([[0,0],[1,0],[0,1],[1,1]])
self.roi=np.array([1,2])
self.elem=triangles_mesh(self.coords,self.topology)

def plot_mesh(self,file_name=None,flag_show_image=1):
fig=plt.figure()
my_axis=fig.add_subplot(111,aspect='equal')
my_axis.triplot(self.coords[:,0],self.coords[:,1],
self.topology,color=[0, 0,0 ],lw=0.4)

plt.yticks([])
plt.xticks([])
my_axis.axis('off')
x_max,y_max=self.coords.max(0)
x_min,y_min=self.coords.min(0)
my_axis.axis([x_min, x_max, y_min, y_max])
plt.draw()
if file_name!=None:

plt.savefig(file_name,transparent=True,format=eps,bbox_inches=tight)
if flag_show_image==1:
plt.show()
plt.close()

def plot_values(self,file_name=None,flag_show_image=1):

fig=plt.figure()
my_axis=fig.add_subplot(111,aspect='equal')
my_axis.add_collection(self.elem.triangles)
#plt.yticks([])
#plt.xticks([])
#my_axis.axis('off')
x_max,y_max=self.coords.max(0)
x_min,y_min=self.coords.min(0)
my_axis.axis([x_min, x_max, y_min, y_max])
fig.canvas.draw()
if file_name!=None:

plt.savefig(file_name,transparent=True,format=eps,bbox_inches=tight)
if flag_show_image==1:
plt.show()

plt.close()

malha_pd=mesh_2D()

malha_pd.plot_mesh(mesh.eps,flag_show_image=0)
malha_pd.plot_mesh(mesh1.eps,flag_show_image=0)
malha_pd.plot_values(values.eps,flag_show_image=1)

# set new values ()
new_values=np.random.rand(malha_pd.topology.shape[0])
malha_pd.elem.triangles.set_array(np.array(new_values))

#plot again: here the problem appears
malha_pd.plot_values(values1.eps,flag_show_image=1)

#--
# END CODE - END CODE
#--

--
5 Ways 

Re: [Matplotlib-users] Some more mplot3d questions

2011-07-21 Thread gary ruben
Hi Ben,
Comments inline...

On Fri, Jul 22, 2011 at 1:31 AM, Benjamin Root ben.r...@ou.edu wrote:


 On Thu, Jul 21, 2011 at 1:10 AM, gary ruben gary.ru...@gmail.com wrote:

 I'm trying to make a surface plot using the latest version of mplot3d
 from the git trunk and I have a couple of questions. The attached
 image is close to what I would like. The associated plot command I am
 using is

 ax.plot_surface(X, Y, Z, rstride=1, cstride=1, alpha=0.8, shade=True,
    cmap=plt.cm.summer,
    color='k',
    facecolors='k',
    lightsource = LightSource(azdeg=0, altdeg=0),
    )

 1. Is there support now to automatically annotate the axis so that a
 multiplier is added, as occurs in 2D plots, or should I do this
 manually by rescaling the data for the moment?

 Yes, offset text is now automatic and should activate in similar manner as
 it does for regular 2D axis formatters.  You were one order of magnitude off
 from automatically triggering it.  Also, I should note that it might be
 better to use ax = fig.gca(projection='3d') instead of ax = Axes3D(fig)
 because the former will leave more of a margin, which would allow the offset
 text to be fully visible.

Thanks. That's actually what I am doing but I cropped the output image
before attaching it.

 If you want the full figure area, then you may
 need to fiddle with the ax.zaxis._axinfo['label']['space_factor'] to bring
 it and the axis label closer to the axis.

Thanks. That's useful to know.

 The odd thing that I am encountering right now while investigating your
 problem is that I can't seem to force the use of the offset.  It could just
 be that I am doing it wrong, but I will look closer.

Yes, I had set 'axes.formatter.limits' : (-2, 2) hoping to trigger it
- I guess that's what you tried.

 2. Currently, it doesn't appear possible to shade the surface patches
 according to just a base facecolor and their orientation to a light
 source. Do I have to define a new colormap with a constant/single
 colour to achieve this?

 Looking over the plot_surface code, this appears to be the case, however,
 looking back over the LightSource code, I believe it might be possible to
 update plot_surface to operate on situations where no cmap is specified.  I
 will take a look today at that possibility and see if I can get it out for
 the v1.1.0 release.

That would be great - it is a very good way to visualize a surface so
it should be made as simple as possible.

 3. I have set alpha=0.8 to allow the wireframe lines to show through a
 little. When shade=False, the wireframe is visible but I lose
 orientation-based shading. Is there a way to overlay the wireframe
 properly when shade=True?


 In plot_surface, when shade=True, it appears that both the facecolors and
 the edgecolors are set to the same colors.  The only reason why the lines
 show up when you set transparency is that that alpha value is applied only
 to the faces and not the edges.  Specifically, the logic is as follows:

 if fcolors is specified, then set that color for both facecolor and
 edgecolor.
 Else, if a cmap is specified, then give the polygon collection the data,
 limits and norm it needs to determine color itself.
 Else, then use the value of color to specify only the facecolors.

 I think the first branch of this logic is a bit wonky.

I agree, since fcolors must be specified in order to trigger the
lightsource-based shading.

 I am inclined to
 make a small change that would only set the edgecolors if 'edgecolors' was
 not provided as a kwarg.  This would enable users to specify the edgecolor
 they want without worrying about something else over-riding it.  The only
 problem seems to be that there would be no shading of these grid lines.
 Would that still be acceptable to you?

Absolutely acceptable. In fact I think it is preferable not to shade them.

 Thanks for your valuable feedback!
 Ben Root

Thanks for being responsive to it :)
regards,
Gary

--
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks  Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users