Plotting arrows

Hello,

This is my first message to the mailing list. I send a
patch to plot arrows as markers. I hope someone find
it usefull.

I needed to plot arrows as markers and I did not find
how to do it easily. Finally I changed some of the
source code (axes.py and lines.py) to do this.

To plot an arrow you have to write an 'a' plus a
number which defines the direction of the arrow. The
directions are the same that the ones in the numerical
keyboard, i.e., if you want to plot a green arrow
pointing to the left-bottom you will have to write the
string 'ga1' or 'a1g'.

I send the files for the version 0.82 of matplotlib (I
can not run properly the version 0.87 by now because I
have problems with colours and the axes(??!)). Here
are the diff outputs for the two files:

--- axes.py 2005-08-04 20:19:57.000000000 +0200
+++ axes_original.py 2005-06-15 20:50:44.000000000
+0200
@@ -89,30 +89,6 @@
     if fmt.find('-.')>=0:
         linestyle = '-.'
         fmt = fmt.replace('-.', '')
- if fmt.find('a1')>=0:
- marker = 'a1'
- fmt = fmt.replace('a1', '')
- if fmt.find('a2')>=0:
- marker = 'a2'
- fmt = fmt.replace('a2', '')
- if fmt.find('a3')>=0:
- marker = 'a3'
- fmt = fmt.replace('a3', '')
- if fmt.find('a4')>=0:
- marker = 'a4'
- fmt = fmt.replace('a4', '')
- if fmt.find('a6')>=0:
- marker = 'a6'
- fmt = fmt.replace('a6', '')
- if fmt.find('a7')>=0:
- marker = 'a7'
- fmt = fmt.replace('a7', '')
- if fmt.find('a8')>=0:
- marker = 'a8'
- fmt = fmt.replace('a8', '')
- if fmt.find('a9')>=0:
- marker = 'a9'
- fmt = fmt.replace('a9', '')

     chars = [c for c in fmt]

--- lines.py 2005-08-04 20:19:57.000000000
+0200
+++ lines_original.py 2005-06-15 00:21:21.000000000
+0200
@@ -27,8 +27,7 @@
lineStyles = {'-':1, '--':1, '-.':1, ':':1,
'steps':1, 'None':1}
lineMarkers = {'.':1, ',':1, 'o':1, '^':1, 'v':1,
'<':1, '>':1, 's':1,
                   '+':1, 'x':1, 'd':1, 'D':1, '|':1,
'_':1, 'h':1, 'H':1,
- 'p':1, '1':1, '2':1, '3':1, '4':1,
'a1':1, 'a2':1,
- 'a3':1, 'a4':1, 'a6':1, 'a7':1,
'a8':1, 'a9':1,
+ 'p':1, '1':1, '2':1, '3':1, '4':1,
                   TICKLEFT:1,
                   TICKRIGHT:1,
                   TICKUP:1,
@@ -109,14 +108,6 @@
         '2' : '_draw_tri_up',
         '3' : '_draw_tri_left',
         '4' : '_draw_tri_right',
- 'a1' : '_draw_arrow_left_down',
- 'a2' : '_draw_arrow_down',
- 'a3' : '_draw_arrow_right_down',
- 'a4' : '_draw_arrow_left',
- 'a6' : '_draw_arrow_right',
- 'a7' : '_draw_arrow_left_up',
- 'a8' : '_draw_arrow_up',
- 'a9' : '_draw_arrow_right_up',
         's' : '_draw_square',
         'p' : '_draw_pentagon',
         'h' : '_draw_hexagon1',
@@ -1136,139 +1127,6 @@
                 renderer.draw_line(gc, x-offset,
y-offset, x+offset, y+offset)
                 renderer.draw_line(gc, x-offset,
y+offset, x+offset, y-offset)

-#Empiezan mis 8 flechas

···

-
- def _draw_arrow_down(self, renderer, gc, xt, yt):
- offset =
0.5*renderer.points_to_pixels(self._markersize)
- if self._newstyle:
- path = agg.path_storage()
- path.move_to(0, +offset)
- path.line_to(0, -offset)
- path.line_to(-offset, 0)
- path.move_to(+offset, 0)
- path.line_to(0, -offset)
- renderer.draw_markers(gc, path, None, xt,
yt, self._transform)
- else:
- for (x,y) in zip(xt, yt):
- renderer.draw_line(gc, x, y+offset,
x, y-offset)
- renderer.draw_line(gc, x, y-offset,
x+offset, y)
- renderer.draw_line(gc, x, y-offset,
x-offset, y)
-
- def _draw_arrow_left_down(self, renderer, gc, xt,
yt):
- offset =
0.5*renderer.points_to_pixels(self._markersize)
- if self._newstyle:
- path = agg.path_storage()
- path.move_to(+offset, +offset)
- path.line_to(-offset, -offset)
- path.line_to(-offset, 0)
- path.move_to(0, -offset)
- path.line_to(-offset, -offset)
- renderer.draw_markers(gc, path, None, xt,
yt, self._transform)
- else:
- for (x,y) in zip(xt, yt):
- renderer.draw_line(gc, x+offset,
y+offset, x-offset, y-offset)
- renderer.draw_line(gc, x-offset,
y-offset, x-offset, y)
- renderer.draw_line(gc, x-offset,
y-offset, x, y-offset)
-
- def _draw_arrow_right_down(self, renderer, gc,
xt, yt):
- offset =
0.5*renderer.points_to_pixels(self._markersize)
- if self._newstyle:
- path = agg.path_storage()
- path.move_to(-offset, +offset)
- path.line_to(+offset, -offset)
- path.line_to(+offset, 0)
- path.move_to(0, -offset)
- path.line_to(+offset, -offset)
- renderer.draw_markers(gc, path, None, xt,
yt, self._transform)
- else:
- for (x,y) in zip(xt, yt):
- renderer.draw_line(gc, x-offset,
y+offset, x+offset, y-offset)
- renderer.draw_line(gc, x+offset,
y-offset, x+offset, y)
- renderer.draw_line(gc, x+offset,
y-offset, x, y-offset)
-
- def _draw_arrow_left(self, renderer, gc, xt, yt):
- offset =
0.5*renderer.points_to_pixels(self._markersize)
- if self._newstyle:
- path = agg.path_storage()
- path.move_to(+offset,0)
- path.line_to(-offset,0)
- path.line_to(0,+offset)
- path.move_to(-offset, 0)
- path.line_to(0, -offset)
- renderer.draw_markers(gc, path, None, xt,
yt, self._transform)
- else:
- for (x,y) in zip(xt, yt):
- renderer.draw_line(gc, x+offset, y,
x-offset, y)
- renderer.draw_line(gc, x-offset, y,
x, y+offset)
- renderer.draw_line(gc, x-offset, y,
x, y-offset)
-
- def _draw_arrow_right(self, renderer, gc, xt,
yt):
- offset =
0.5*renderer.points_to_pixels(self._markersize)
- if self._newstyle:
- path = agg.path_storage()
- path.move_to(-offset,0)
- path.line_to(+offset,0)
- path.line_to(0,+offset)
- path.move_to(+offset, 0)
- path.line_to(0, -offset)
- renderer.draw_markers(gc, path, None, xt,
yt, self._transform)
- else:
- for (x,y) in zip(xt, yt):
- renderer.draw_line(gc, x+offset, y,
x-offset, y)
- renderer.draw_line(gc, x+offset, y,
x, y+offset)
- renderer.draw_line(gc, x+offset, y,
x, y-offset)
-
- def _draw_arrow_left_up(self, renderer, gc, xt,
yt):
- offset =
0.5*renderer.points_to_pixels(self._markersize)
- if self._newstyle:
- path = agg.path_storage()
- path.move_to(+offset, -offset)
- path.line_to(-offset, +offset)
- path.line_to(-offset, 0)
- path.move_to(0, +offset)
- path.line_to(-offset, +offset)
- renderer.draw_markers(gc, path, None, xt,
yt, self._transform)
- else:
- for (x,y) in zip(xt, yt):
- renderer.draw_line(gc, x-offset,
y+offset, x+offset, y-offset)
- renderer.draw_line(gc, x-offset,
y+offset, x, y+offset)
- renderer.draw_line(gc, x-offset,
y+offset, x-offset, y)
-
- def _draw_arrow_up(self, renderer, gc, xt, yt):
- offset =
0.5*renderer.points_to_pixels(self._markersize)
- if self._newstyle:
- path = agg.path_storage()
- path.move_to(0, -offset)
- path.line_to(0, +offset)
- path.line_to(-offset, 0)
- path.move_to(+offset, 0)
- path.line_to(0, +offset)
- renderer.draw_markers(gc, path, None, xt,
yt, self._transform)
- else:
- for (x,y) in zip(xt, yt):
- renderer.draw_line(gc, x, y+offset,
x, y-offset)
- renderer.draw_line(gc, x, y+offset,
x+offset, y)
- renderer.draw_line(gc, x, y+offset,
x-offset, y)
-
- def _draw_arrow_right_up(self, renderer, gc, xt,
yt):
- offset =
0.5*renderer.points_to_pixels(self._markersize)
- if self._newstyle:
- path = agg.path_storage()
- path.move_to(-offset, -offset)
- path.line_to(+offset, +offset)
- path.line_to(+offset, 0)
- path.move_to(0, +offset)
- path.line_to(+offset, +offset)
- renderer.draw_markers(gc, path, None, xt,
yt, self._transform)
- else:
- for (x,y) in zip(xt, yt):
- renderer.draw_line(gc, x+offset,
y+offset, x-offset, y-offset)
- renderer.draw_line(gc, x+offset,
y+offset, x+offset, y)
- renderer.draw_line(gc, x+offset,
y+offset, x, y+offset)
-
-#Terminan mis 8 flechas
-
-
     def update_from(self, other):
         'copy properties from other to self'
         Artist.update_from(self, other)

-------------------------------------

I think it would not be difficult to do something
similar for the last version. The shape of the arrows
can be improved to look better. This patch is only an
idea, the problem is to add new non-standard marker
names, if anyone knows a smart way of doing this it
would be apreciated. That's all.

Thank you for your fabulous module.
Pepe.

______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y m�viles desde 1 c�ntimo por minuto.
http://es.voice.yahoo.com

You might want to do something with a LineCollection instead. TRy the enclosed code. Is that what you are looking for?

I intend, some day, to clean this up and submit it to MPL, but in the meantime, feel free to use or hack on it.

By the way, do you have a sample of what your code produces?

-Chris

VecPlot.py (2.4 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...236...