Revision: 7721
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7721&view=rev
Author: leejjoon
Date: 2009-09-08 17:42:58 +0000 (Tue, 08 Sep 2009)
Log Message:
-----------
AxesGrid: implemented axisline style
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py
Added Paths:
-----------
trunk/matplotlib/examples/axes_grid/demo_axisline_style.py
trunk/matplotlib/lib/mpl_toolkits/axes_grid/axisline_style.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2009-09-08 17:42:47 UTC (rev 7720)
+++ trunk/matplotlib/CHANGELOG 2009-09-08 17:42:58 UTC (rev 7721)
@@ -1,3 +1,6 @@
+2009-09-07 AxesGrid : implemented axisline style.
+ Added a demo examples/axes_grid/demo_axisline_style.py- JJL
+
2009-09-04 Make the textpath class as a separate moduel
(textpath.py). Add support for mathtext and tex.- JJL
Added: trunk/matplotlib/examples/axes_grid/demo_axisline_style.py
===================================================================
--- trunk/matplotlib/examples/axes_grid/demo_axisline_style.py
(rev 0)
+++ trunk/matplotlib/examples/axes_grid/demo_axisline_style.py 2009-09-08
17:42:58 UTC (rev 7721)
@@ -0,0 +1,21 @@
+
+from mpl_toolkits.axes_grid.axislines import SubplotZero
+import matplotlib.pyplot as plt
+import numpy as np
+
+if __name__ == "__main__":
+ fig = plt.figure(1)
+ ax = SubplotZero(fig, 111)
+ fig.add_subplot(ax)
+
+ for direction in ["xzero", "yzero"]:
+ ax.axis[direction].set_axisline_style("->")
+ ax.axis[direction].set_visible(True)
+
+ for direction in ["left", "right", "bottom", "top"]:
+ ax.axis[direction].set_visible(False)
+
+ x = np.linspace(-0.5, 1., 100)
+ ax.plot(x, np.sin(x*np.pi))
+
+ plt.show()
Added: trunk/matplotlib/lib/mpl_toolkits/axes_grid/axisline_style.py
===================================================================
--- trunk/matplotlib/lib/mpl_toolkits/axes_grid/axisline_style.py
(rev 0)
+++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/axisline_style.py
2009-09-08 17:42:58 UTC (rev 7721)
@@ -0,0 +1,148 @@
+from matplotlib.patches import _Style, FancyArrowPatch
+from matplotlib.transforms import IdentityTransform
+from matplotlib.path import Path
+import numpy as np
+
+class AxislineStyle(_Style):
+ """
+ :class:`AxislineStyle` is a container class which defines style classes
+ for AxisArtists.
+
+ An instance of any axisline style class is an callable object,
+ whose call signature is ::
+
+ __call__(self, axis_artist, path, transform)
+
+ When called, this should return a mpl artist with following
+ methods implemented. ::
+
+ def set_path(self, path):
+ # set the path for axisline.
+
+ def set_line_mutation_scale(self, scale):
+ # set the scale
+
+ def draw(self, renderer):
+ # draw
+
+
+ """
+
+ _style_list = {}
+
+
+ class _Base(object):
+ # The derived classes are required to be able to be initialized
+ # w/o arguments, i.e., all its argument (except self) must have
+ # the default values.
+
+ def __init__(self):
+ """
+ initializtion.
+ """
+ super(AxislineStyle._Base, self).__init__()
+
+
+
+
+ def __call__(self, axis_artist, transform):
+ """
+ Given the AxisArtist instance, and transform for the path
+ (set_path method), return the mpl artist for drawing the axis line.
+ """
+
+ return self.new_line(axis_artist, transform)
+
+
+ class SimpleArrow(_Base):
+ """
+ A simple arrow.
+ """
+
+
+ class ArrowAxisline(FancyArrowPatch):
+ """
+ The artist class that will be returend for SimpleArrow style.
+ """
+ def __init__(self, axis_artist, line_path, transform,
+ line_mutation_scale):
+ self._axis_artist = axis_artist
+ self._line_transform = transform
+ self._line_path = line_path
+ self._line_mutation_scale = line_mutation_scale
+
+ FancyArrowPatch.__init__(self,
+ path=self._line_path,
+ arrowstyle="->",
+ arrow_transmuter=None,
+ patchA=None,
+ patchB=None,
+ shrinkA=0.,
+ shrinkB=0.,
+ mutation_scale=line_mutation_scale,
+ mutation_aspect=None,
+ transform=IdentityTransform(),
+ )
+
+ def set_line_mutation_scale(self, scale):
+ self.set_mutation_scale(scale*self._line_mutation_scale)
+
+ def _extend_path(self, path, mutation_size=10):
+ """
+ Extend the path to make a room for drawing arrow.
+ """
+ from matplotlib.bezier import get_cos_sin
+
+ x0, y0 = path.vertices[-2]
+ x1, y1 = path.vertices[-1]
+ cost, sint = get_cos_sin(x0, y0, x1, y1)
+
+ d = mutation_size * 1.
+ x2, y2 = x1 + cost*d, y1+sint*d
+
+ if path.codes is None:
+ _path = Path(np.concatenate([path.vertices, [[x2, y2]]]))
+ else:
+ _path = Path(np.concatenate([path.vertices, [[x2, y2]]]),
+ np.concatenate([path.codes, [Path.LINETO]]))
+
+ return _path
+
+ def set_path(self, path):
+ self._line_path = path
+
+ def draw(self, renderer):
+ """
+ Draw the axis line.
+ 1) transform the path to the display cooridnate.
+ 2) extend the path to make a room for arrow
+ 3) update the path of the FancyArrowPatch.
+ 4) draw
+ """
+ path_in_disp =
self._line_transform.transform_path(self._line_path)
+ mutation_size = self.get_mutation_scale()
#line_mutation_scale()
+ extented_path = self._extend_path(path_in_disp,
+ mutation_size=mutation_size)
+
+ self._path_original = extented_path
+ FancyArrowPatch.draw(self, renderer)
+
+
+ def __init__(self, size=1):
+ """
+ *size*
+ size of the arrow as a fraction of the ticklabel size.
+ """
+
+ self.size = size
+ super(AxislineStyle.SimpleArrow, self).__init__()
+
+ def new_line(self, axis_artist, transform):
+
+ linepath = Path([(0,0), (0, 1)])
+ axisline = self.ArrowAxisline(axis_artist, linepath, transform,
+ line_mutation_scale=self.size)
+ return axisline
+
+
+ _style_list["->"] = SimpleArrow
Modified: trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py
===================================================================
--- trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py 2009-09-08
17:42:47 UTC (rev 7720)
+++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py 2009-09-08
17:42:58 UTC (rev 7721)
@@ -63,9 +63,9 @@
import matplotlib.lines as mlines
+from axisline_style import AxislineStyle
-
class BezierPath(mlines.Line2D):
def __init__(self, path, *kl, **kw):
@@ -184,6 +184,8 @@
"""
self.label_direction = label_direction
+ self.delta1, self.delta2 = 0.00001, 0.00001
+
def update_lim(self, axes):
pass
@@ -463,8 +465,8 @@
# check if the tick point is inside axes
c2 = tr2ax.transform_point(c)
- delta=0.00001
- if 0. -delta<= c2[self.nth_coord] <= 1.+delta:
+ #delta=0.00001
+ if 0. -self.delta1<= c2[self.nth_coord] <= 1.+self.delta2:
yield c, angle, l
return _f(majorLocs, majorLabels), _f(minorLocs, minorLabels)
@@ -551,7 +553,8 @@
c[self.nth_coord] = x
c1, c2 = tr2ax.transform_point(c)
if 0. <= c1 <= 1. and 0. <= c2 <= 1.:
- yield c, angle, l
+ if 0. - self.delta1 <= [c1, c2][self.nth_coord] <= 1.
+ self.delta2:
+ yield c, angle, l
return _f(majorLocs, majorLabels), _f(minorLocs, minorLabels)
@@ -964,6 +967,8 @@
if minor_tick_pad is None:
self.minor_tick_pad = rcParams['%s.minor.pad'%axis_name]
+ self._axisline_style = None
+
self._init_line()
self._init_ticks()
self._init_offsetText(self._axis_artist_helper.label_direction)
@@ -973,6 +978,7 @@
self._rotate_label_along_line = False
+
def set_rotate_label_along_line(self, b):
self._rotate_label_along_line = b
@@ -986,16 +992,61 @@
return self._axis_artist_helper
+ def set_axisline_style(self, axisline_style=None, **kw):
+ """
+ Set the axisline style.
+
+ *axislin_style* can be a string with axisline style name with optional
+ comma-separated attributes. Alternatively, the attrs can
+ be provided as keywords.
+
+ set_arrowstyle("->,size=1.5")
+ set_arrowstyle("->", size=1.5)
+
+ Old attrs simply are forgotten.
+
+ Without argument (or with arrowstyle=None), return
+ available styles as a list of strings.
+ """
+
+ if axisline_style==None:
+ return AxislineStyle.pprint_styles()
+
+ if isinstance(axisline_style, AxislineStyle._Base):
+ self._axisline_style = axisline_style
+ else:
+ self._axisline_style = AxislineStyle(axisline_style, **kw)
+
+
+ self._init_line()
+
+
+ def get_axisline_style(self):
+ """
+ return the current axisline style.
+ """
+ return self._axisline_style
+
def _init_line(self):
+ """
+ Initialize the *line* artist that is responsible to draw the axis line.
+ """
tran = self._axis_artist_helper.get_line_transform(self.axes) \
+ self.offset_transform
- self.line = BezierPath(self._axis_artist_helper.get_line(self.axes),
- color=rcParams['axes.edgecolor'],
- linewidth=rcParams['axes.linewidth'],
- transform=tran)
+ axisline_style = self.get_axisline_style()
+ if axisline_style is None:
+ self.line =
BezierPath(self._axis_artist_helper.get_line(self.axes),
+ color=rcParams['axes.edgecolor'],
+ linewidth=rcParams['axes.linewidth'],
+ transform=tran)
+ else:
+ self.line = axisline_style(self, transform=tran)
+
def _draw_line(self, renderer):
self.line.set_path(self._axis_artist_helper.get_line(self.axes))
+ if self.get_axisline_style() is not None:
+ self.line.set_line_mutation_scale(self.major_ticklabels.get_size())
self.line.draw(renderer)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins