hst_demo not available anymore?

Hi, is there a way to have the hst_demo.py back on line (in

    > the screenshots)? I would need it desesperately! thanks!!!
    > Eric

Well, I don't want anyone getting desperate around here :slight_smile:

It's back up -- thanks for letting me know.

JDH

Hi,

I needed to see visualize a set of points in 3D (scatter plot) and to be able to rotate the axes easily in a way similar to gnuplot.
I have thus written a short python routine using matplotlib for the visu part (attached below).
It works simply by doing something like:

···

###########################################
x = array([0.,1.,2.,3.])
y = array([1.,0.,3.,2.])
z = array([4.,3.,0.,1.])

try = pxyz(x, y, z, labx="x", laby=y", labz="z")

###########################################

It does show the 4 points in projection, including the projection of the x,y,z axis. And each time you move the mouse within the figure, it will move the projection accordingly, showing the 3D scatter plots and the 3 unit axes again.
(the projection is defined via 2 rotation angles, theta - around x - and phi - around z).

Now I realize this is really a naive way of doing such an exercise. The updating (projecting, refreshing, and reploting all points everytime, positions of the axis labels, etc) is very far from optimal (slow and somewhat ugly) mostly because I am a beginner here. So I was wondering if anyone on-line had produced a similar but somewhat refined version of this, or if you had any suggestion of how to improve the speed/efficiency, esthetic and functionality of such a routine? At the moment I am plotting 48 points... But I can imagine such a routine could just be unusable with 1000 points...

Any input is welcome!!!
Thanks,

Eric

def rotaxe(x,y,rotangle=45.) :
   rotangle = rotangle * pi / 180.
   xp = x * cos(rotangle) + y * sin(rotangle)
   yp = - x * sin(rotangle) + y * cos(rotangle)
   return xp, yp

def projpoint(x,y,z,theta=45.,phi=0.) :
   xp, y1 = rotaxe(x,y,rotangle=phi)
   yp, zp = rotaxe(y1,z,rotangle=theta)
   return xp, yp, zp

class pxyz :

   def __init__(self, x, y, z, theta=45., phi=140., labx="x", laby="y", labz="z"):

      self.x = x
      self.y = y
      self.z = z
      self.labx = labx
      self.laby = laby
      self.labz = labz
      self.theta = theta
      self.phi = phi
      self.startx = min(self.x)
      self.starty = min(self.y)
      self.startz = min(self.z)
      self.endx = max(self.x)
      self.endy = max(self.y)
      self.endz = max(self.z)
      self.rangex = self.endx - self.startx
      self.rangey = self.endy - self.starty
      self.rangez = self.endz - self.startz
      self.axex = array([1,0,0])
      self.axey = array([0,1,0])
      self.axez = array([0,0,1])
      if self.rangex != 0. :
         self.xn = (self.x - self.startx) / self.rangex
      else :
         self.xn = zeros(shape(self.x), Float)
      if self.rangey != 0. :
         self.yn = (self.y - self.starty) / self.rangey
      else :
         self.yn = zeros(shape(self.y), Float)
      if self.rangez != 0. :
         self.zn = (self.z - self.startz) / self.rangez
      else :
         self.zn = zeros(shape(self.z), Float)

      fig = gcf()
      self.w = fig.get_figwidth()
      self.h = fig.get_figheight()
      self.plotxyz()
      connect('motion_notify_event', self.on_move)

   def plotxyz(self) :
      clf()
      ioff()
        xp, yp, zp = projpoint(self.axex, self.axey, self.axez, theta=self.theta, phi=self.phi)
      plot([0.,xp[0]],[0.,yp[0]])
      plot([0.,xp[1]],[0.,yp[1]])
      plot([0.,xp[2]],[0.,yp[2]])
      eps = 0.02
      text(xp[0]+eps,yp[0]+eps, self.labx)
      text(xp[1]+eps,yp[1]+eps, self.laby)
      text(xp[2]+eps,yp[2]+eps, self.labz)
      text(xp[0],yp[0], str("%5.3f"%self.endx))
      text(xp[1],yp[1], str("%5.3f"%self.endy))
      text(xp[2],yp[2], str("%5.3f"%self.endz))
      text(xp[0]/10.,yp[0]/10., str("%5.3f"%self.startx))
      text(xp[1]/10.,yp[1]/10., str("%5.3f"%self.starty))
      text(xp[2]/10.,yp[2]/10., str("%5.3f"%self.startz))
      xpn, ypn, zpn = projpoint(self.xn, self.yn, self.zn, theta=self.theta, phi=self.phi)
      scatter(xpn, ypn)
      ion()
      draw()
      axis('off')
      return xpn, ypn, zpn

   def on_move(self, event):
       # get the x and y pixel coords
       x, y = event.x, event.y
       self.theta = x * 3.6 / self.w
       self.phi = y * 3.6 / self.h
         if event.inaxes:
          self.plotxyz()

--

Observatoire de Lyon emsellem@...419...
9 av. Charles-Andre tel: +33 4 78 86 83 84
69561 Saint-Genis Laval Cedex fax: +33 4 78 86 83 86
France http://www-obs.univ-lyon1.fr/eric.emsellem

Hi Eric,

Could you post a complete example? I tried to construct a script from what you
posted, and got the following:

(test.py:10899): Gdk-CRITICAL **: gdk_pixmap_new: assertion `(drawable !=
NULL) || (depth != -1)' failed
Traceback (most recent call last):
  File "test.py", line 98, in ?
    s = pxyz(x, y, z, labx="x", laby="y", labz="z")
  File "test.py", line 55, in __init__
    self.plotxyz()
  File "test.py", line 81, in plotxyz
    draw()
  File "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line 727, in
draw
    get_current_fig_manager().canvas.draw()
  File "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtk.py",
line 234, in draw
    self._pixmap_prepare (w, h)
  File "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtk.py",
line 291, in _pixmap_prepare
    self._pixmap_height)
RuntimeError: could not create GdkPixmap object

···

On Wednesday 17 August 2005 10:53 am, Eric Emsellem wrote:

Hi,

I needed to see visualize a set of points in 3D (scatter plot) and to be
able to rotate the axes easily in a way similar to gnuplot.
I have thus written a short python routine using matplotlib for the visu
part (attached below).