Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d4d0cc2

Browse files
committed
support for shared axes
svn path=/trunk/matplotlib/; revision=889
1 parent d78e6c4 commit d4d0cc2

8 files changed

Lines changed: 76 additions & 34 deletions

File tree

API_CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
API CHANGES in matplotlib-0.72
2+
3+
Line2D, Text, and Patch copy_properties renamed update_from and
4+
moved into artist base class
5+
16
API CHANGES in matplotlib-0.71
27

38
Significant numerix namespace changes, introduced to resolve

examples/shared_axis_demo.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88
changes in the axis scaling (eg log vs linear). However, it is
99
possible to have differences in tick labeling, eg you can selectively
1010
turn off the tick labels on one axes.
11+
12+
The example below shows how to customize the tick labels on the
13+
various axes. Shared axes share the tick locator, tick formatter,
14+
view limits, and transformation (eg log, linear). But the ticklabels
15+
themselves do not share properties. This is a feature and not a bug,
16+
because you may want to make the tick labels smaller on the upper
17+
axes, eg in the example below.
18+
19+
If you want to turn off the ticklabels for a given axes (eg on
20+
subplot(211) or subplot(212), you cannot do the standard trick
21+
22+
set(ax2, =[])
23+
24+
because this changes the tick Formatter, which is shared among all
25+
axes. But you can alter the visibility of the labels, which is a
26+
property
27+
28+
set( ax2.get_xticklabels(), visible=False)
29+
30+
1131
"""
1232
from pylab import *
1333

@@ -17,10 +37,14 @@
1737
s3 = sin(4*pi*t)
1838
ax1 = subplot(311)
1939
plot(t,s1)
40+
plot(t, s2)
41+
set( ax1.get_xticklabels(), fontsize=6)
2042

2143
## share x only
2244
ax2 = subplot(312, sharex=ax1)
23-
plot(t, s2)
45+
46+
# make these tick labels invisible
47+
set( ax2.get_xticklabels(), visible=False)
2448

2549
# share x and y
2650
ax3 = subplot(313, sharex=ax1, sharey=ax1)

lib/matplotlib/artist.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,14 @@ def set_zorder(self, level):
163163
"""
164164
self.zorder = level
165165

166+
def update_from(self, other):
167+
'copy properties from other to self'
168+
self._transform = other._transform
169+
self._transformSet = other._transformSet
170+
self._visible = other._visible
171+
self._alpha = other._alpha
172+
self.clipbox = other.clipbox
173+
self._clipon = other._clipon
174+
self._lod = other._lod
175+
self._label = other._label
176+

lib/matplotlib/axis.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,12 @@ def _get_tick(self, major):
584584
def _copy_tick_props(self, src, dest):
585585
'Copy the props from src tick to dest tick'
586586
if src is None or dest is None: return
587-
dest.label1.copy_properties(src.label1)
588-
dest.label2.copy_properties(src.label2)
587+
dest.label1.update_from(src.label1)
588+
dest.label2.update_from(src.label2)
589589

590-
dest.tick1line.copy_properties(src.tick1line)
591-
dest.tick2line.copy_properties(src.tick2line)
592-
dest.gridline.copy_properties(src.gridline)
590+
dest.tick1line.update_from(src.tick1line)
591+
dest.tick2line.update_from(src.tick2line)
592+
dest.gridline.update_from(src.gridline)
593593

594594
dest.tick1On = src.tick1On
595595
dest.tick2On = src.tick2On

lib/matplotlib/legend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def _get_handles(self, handles, texts):
217217
ydata = (y-HEIGHT/2)*ones(self._xdata.shape, Float)
218218
legline = Line2D(self._xdata, ydata)
219219
self._set_artist_props(legline)
220-
legline.copy_properties(handle)
220+
legline.update_from(handle)
221221
legline.set_markersize(self.markerscale*legline.get_markersize())
222222
legline.set_data_clipping(False)
223223
ret.append(legline)
@@ -226,7 +226,7 @@ def _get_handles(self, handles, texts):
226226
p = Rectangle(xy=(min(self._xdata), y-3/4*HEIGHT),
227227
width = self.handlelen, height=HEIGHT/2,
228228
)
229-
p.copy_properties(handle)
229+
p.update_from(handle)
230230
self._set_artist_props(p)
231231
ret.append(p)
232232
elif isinstance(handle, LineCollection):

lib/matplotlib/lines.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -722,22 +722,23 @@ def _draw_x(self, renderer, gc, xt, yt):
722722
renderer.draw_line(gc, x-offset, y-offset, x+offset, y+offset)
723723
renderer.draw_line(gc, x-offset, y+offset, x+offset, y-offset)
724724

725-
def copy_properties(self, line):
726-
'copy properties from line to self'
727-
self._linestyle = line._linestyle
728-
self._linewidth = line._linewidth
729-
self._color = line._color
730-
self._markersize = line._markersize
731-
self._markerfacecolor = line._markerfacecolor
732-
self._markeredgecolor = line._markeredgecolor
733-
self._markeredgewidth = line._markeredgewidth
734-
self._dashSeq = line._dashSeq
735-
736-
self._linestyle = line._linestyle
737-
self._marker = line._marker
738-
self._lineFunc = line._lineStyles[line._linestyle]
739-
self._markerFunc = line._markers[line._marker]
740-
self._useDataClipping = line._useDataClipping
725+
def update_from(self, other):
726+
'copy properties from other to self'
727+
Artist.update_from(self, other)
728+
self._linestyle = other._linestyle
729+
self._linewidth = other._linewidth
730+
self._color = other._color
731+
self._markersize = other._markersize
732+
self._markerfacecolor = other._markerfacecolor
733+
self._markeredgecolor = other._markeredgecolor
734+
self._markeredgewidth = other._markeredgewidth
735+
self._dashSeq = other._dashSeq
736+
737+
self._linestyle = other._linestyle
738+
self._marker = other._marker
739+
self._lineFunc = other._lineStyles[other._linestyle]
740+
self._markerFunc = other._markers[other._marker]
741+
self._useDataClipping = other._useDataClipping
741742

742743
def _get_rgb_face(self):
743744
if (self._markerfacecolor is None or

lib/matplotlib/patches.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def __init__(self,
4444
func = getattr(self, func)
4545
func(v)
4646

47-
def copy_properties(self, other):
47+
def update_from(self, other):
48+
Artist.update_from(self, other)
4849
self.set_edgecolor(other.get_edgecolor())
4950
self.set_facecolor(other.get_facecolor())
5051
self.set_fill(other.get_fill())
@@ -194,7 +195,7 @@ def __init__(self, patch, ox, oy, props=None):
194195
self._update()
195196

196197
def _update(self):
197-
self.copy_properties(self.patch)
198+
self.update_from(self.patch)
198199
if self.props is not None:
199200
self.update(self.props)
200201
else:

lib/matplotlib/text.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ def get_rotation(self):
7575
angle = float(self._rotation)
7676
return angle%360
7777

78-
def copy_properties(self, t):
78+
def update_from(self, other):
7979
'Copy properties from t to self'
80-
81-
self._color = t._color
82-
self._multialignment = t._multialignment
83-
self._verticalalignment = t._verticalalignment
84-
self._horizontalalignment = t._horizontalalignment
85-
self._fontproperties = t._fontproperties.copy()
86-
self._rotation = t._rotation
80+
Artist.update_from(self, other)
81+
self._color = other._color
82+
self._multialignment = other._multialignment
83+
self._verticalalignment = other._verticalalignment
84+
self._horizontalalignment = other._horizontalalignment
85+
self._fontproperties = other._fontproperties.copy()
86+
self._rotation = other._rotation
8787

8888

8989
def _get_layout(self, renderer):

0 commit comments

Comments
 (0)