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

Skip to content

Commit c85ea02

Browse files
committed
new transformation / artist constructors
svn path=/trunk/matplotlib/; revision=290
1 parent 6d1517a commit c85ea02

26 files changed

Lines changed: 2435 additions & 210 deletions

.matplotlibrc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,18 @@ axes.labelsize : 12 # fontsize of the x any y labels
110110
axes.labelcolor : k # black
111111

112112
### TICKS
113-
tick.major.size : 5 # major tick size in points
114-
tick.minor.size : 3 # minor tick size in points
113+
tick.major.size : 4 # major tick size in points
114+
tick.minor.size : 2 # minor tick size in points
115+
tick.major.pad : 3 # distance to major tick label in points
116+
tick.minor.pad : 3 # distance to the minor tick label in points
115117
tick.color : k # color of the tick labels
116118
tick.labelsize : 10 # fontsize of the tick labels
117119

120+
### Grids
121+
grid.color : k # grid color
122+
grid.linestyle : : # dotted
123+
grid.linewidth : 0.5 # in points
124+
118125
### FIGURE
119126
figure.figsize : 8, 6 # figure size in inches
120127
figure.dpi : 80 # figure dots per inch

API_CHANGES

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,128 @@
1+
API CHANGES in matplotlib-0.54
2+
3+
Autoscaling:
4+
5+
The x and y axis instances no longer have autoscale view. These are
6+
handled by axes.autoscale_view
7+
8+
Axes creation:
9+
10+
You should not instantiate your own Axes any more using the OO API.
11+
Rather, create a Figure as before and in place of
12+
13+
f = Figure(figsize=(5,4), dpi=100)
14+
a = Subplot(f, 111)
15+
f.add_axis(a)
16+
17+
use
18+
19+
f = Figure(figsize=(5,4), dpi=100)
20+
a = f.add_subplot(111)
21+
22+
That is, add_axis no longer exists and is replaced by
23+
24+
add_axes(rect, axisbg=defaultcolor, frameon=True)
25+
add_subplot(num, axisbg=defaultcolor, frameon=True)
26+
27+
Artist methods:
28+
29+
If you define your own Artists, you need to rename the _draw method
30+
to draw
31+
32+
Bounding boxes.
33+
34+
matplotlib.transforms.Bound2D is replaced by
35+
matplotlib.transforms.Bbox. If you want to construct a bbox from
36+
left, bottom, width, height (the signature for Bound2D), use
37+
matplotlib.transforms.lbwh_to_bbox, as in
38+
39+
bbox = clickBBox = lbwh_to_bbox(left, bottom, width, height)
40+
41+
The Bbox has a different API than the Bound2D. Eg, if you want to
42+
get the width and height of the bbox
43+
44+
OLD
45+
width = self.figure.bbox.x.interval()
46+
height = self.figure.bbox.y.interval()
47+
48+
New
49+
width = self.figure.bbox.width()
50+
height = self.figure.bbox.height()
51+
52+
53+
54+
55+
Object constructors:
56+
57+
You no longer pass the bbox, dpi, or transforms to the various
58+
Artist constructors. The old way or creating lines and rectangles
59+
was cumbersome because you had to pass so many attributes to the
60+
Line2D and Rectangle classes not related directly to the gemoetry
61+
and properties of the object. Now default values are added to the
62+
object when you call axes.add_line or axes.add_patch, so they are
63+
hidden from the user.
64+
65+
If you want to define a custom transformation on these objects, call
66+
o.set_transform(trans) where trans is a Transformation instance.
67+
68+
In prior versions of you wanted to add a custom line in data coords,
69+
you would have to do
70+
71+
l = Line2D(dpi, bbox, x, y,
72+
color = color,
73+
transx = transx,
74+
transy = transy,
75+
)
76+
77+
now all you need is
78+
79+
l = Line2D(x, y, color=color)
80+
81+
and the axes will set the transformation for you (unless you have
82+
set your own already, in which case it will eave it unchanged)
83+
84+
Transformations:
85+
86+
The entire transformation architecture has been rewritten.
87+
Previously the x and y transformations where stored in the xaxis and
88+
yaxis insstances. The problem with this approach is it only allows
89+
for separable transforms (where the x and y transformations don't
90+
depend on one another). But for cases like polar, they do. Now
91+
transformations operate on x,y together. There is a new base class
92+
matplotlib.transforms.Transformation and two concrete
93+
implemetations, matplotlib.transforms.SeparableTransformation and
94+
matplotlib.transforms.Affine. The SeparableTransformation is
95+
constructed with the bounding box of the input (this determines the
96+
rectangular coordinate system of the input, ie the x and y view
97+
limits), the bounding box of the display, and possibily nonlinear
98+
transformations of x and y. The 2 most frequently used
99+
transformations, data cordinates -> display and axes coordinates ->
100+
display are available as ax.transData and ax.transAxes. See
101+
alignment_demo.py which uses axes coords.
102+
103+
Also, the transformations should be much faster now, for two reasons
104+
105+
* they are written entirely in extension code
106+
107+
* because they operate on x and y together, they can do the entire
108+
transformation in one loop. Earlier I did something along the
109+
lines of
110+
111+
xt = sx*func(x) + tx
112+
yt = sy*func(y) + ty
113+
114+
Although this was done in numerix, it still involves 6 length(x)
115+
for-loops (the multiply, add, and function evaluation each for x
116+
and y). Now all of that is done in a single pass.
117+
118+
See unit/transforms_unit.py for many examples using the new
119+
transformations.
120+
121+
122+
123+
124+
125+
1126
API changes at 0.50
2127

3128
* refactored Figure class so it is no longer backend dependent.

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
New entries should be added at the top
22
------------------------------------------------------------
33

4+
2004-05-15 Rewrote transformation class in extension code, simplified
5+
all the artist constructors - JDH
6+
47
2004-05-14 Modified the type definitions in the numarray side of
58
numerix so that they are Numeric typecodes and can be
69
used with Numeric compilex extensions. The original

TODO

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,17 @@
345345

346346
-- expose line set dashes
347347

348-
-- fix vertical layout in PS
348+
-- fix vertical layout in PS
349+
350+
-- DONE y clipping broken
351+
352+
-- fix data lim problem with image; see image_demo2
353+
354+
-- handle space in roman/font text
355+
356+
-- scatter demos whacked
357+
358+
-- fix small artist bboxing problems
359+
360+
-- fix backend image area problem for vert text in GTK - related to
361+
rect I think

examples/alignment_test.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,87 +8,75 @@
88
from matplotlib.matlab import *
99
from matplotlib.lines import Line2D
1010
from matplotlib.patches import Rectangle
11-
from matplotlib.transforms import Transform
1211

1312
# build a rectangle in axes coords
1413
left, width = .25, .5
1514
bottom, height = .25, .5
1615
right = left + width
1716
top = bottom + height
1817
ax = gca()
19-
p = Rectangle(ax.dpi, ax.bbox,
20-
(left, bottom), width, height,
18+
p = Rectangle((left, bottom), width, height,
2119
fill=False,
22-
transx=ax.xaxis.transAxis,
23-
transy=ax.yaxis.transAxis)
20+
)
21+
p.set_transform(ax.transAxes)
2422
p.set_clip_on(False)
2523
ax.add_patch(p)
2624

2725

2826
ax.text(left, bottom, 'left top',
2927
horizontalalignment='left',
3028
verticalalignment='top',
31-
transx=ax.xaxis.transAxis,
32-
transy=ax.yaxis.transAxis)
29+
transform=ax.transAxes)
3330

3431
ax.text(left, bottom, 'left bottom',
3532
horizontalalignment='left',
3633
verticalalignment='bottom',
37-
transx=ax.xaxis.transAxis,
38-
transy=ax.yaxis.transAxis)
34+
transform=ax.transAxes)
3935

4036
ax.text(right, top, 'right bottom',
4137
horizontalalignment='right',
4238
verticalalignment='bottom',
43-
transx=ax.xaxis.transAxis,
44-
transy=ax.yaxis.transAxis)
39+
transform=ax.transAxes)
4540

4641
ax.text(right, top, 'right top',
4742
horizontalalignment='right',
4843
verticalalignment='top',
49-
transx=ax.xaxis.transAxis,
50-
transy=ax.yaxis.transAxis)
44+
transform=ax.transAxes)
5145

5246
ax.text(right, bottom, 'center top',
5347
horizontalalignment='center',
5448
verticalalignment='top',
55-
transx=ax.xaxis.transAxis,
56-
transy=ax.yaxis.transAxis)
49+
transform=ax.transAxes)
5750

5851
ax.text(left, 0.5*(bottom+top), 'right center',
5952
horizontalalignment='right',
6053
verticalalignment='center',
6154
rotation='vertical',
62-
transx=ax.xaxis.transAxis,
63-
transy=ax.yaxis.transAxis)
55+
transform=ax.transAxes)
6456

6557
ax.text(left, 0.5*(bottom+top), 'left center',
6658
horizontalalignment='left',
6759
verticalalignment='center',
6860
rotation='vertical',
69-
transx=ax.xaxis.transAxis,
70-
transy=ax.yaxis.transAxis)
61+
transform=ax.transAxes)
7162

7263
ax.text(0.5*(left+right), 0.5*(bottom+top), 'middle',
7364
horizontalalignment='center',
7465
verticalalignment='center',
75-
transx=ax.xaxis.transAxis,
76-
transy=ax.yaxis.transAxis)
66+
transform=ax.transAxes)
7767

7868
ax.text(right, 0.5*(bottom+top), 'centered',
7969
horizontalalignment='center',
8070
verticalalignment='center',
8171
rotation='vertical',
82-
transx=ax.xaxis.transAxis,
83-
transy=ax.yaxis.transAxis)
72+
transform=ax.transAxes)
8473

8574
ax.text(left, top, 'rotated',
8675
horizontalalignment='center',
8776
verticalalignment='center',
8877
rotation=45,
89-
transx=ax.xaxis.transAxis,
90-
transy=ax.yaxis.transAxis)
78+
transform=ax.transAxes)
9179

9280
axis('off')
93-
savefig('alignment_test', dpi=100)
81+
#savefig('alignment_test', dpi=100)
9482
show()

examples/anim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def updatefig(*args):
1818
updatefig.count += 1
1919
if updatefig.count>59: updatefig.count=0
20-
lines[0].set_data(ind,X[:,updatefig.count])
20+
lines[0].set_ydata(X[:,updatefig.count])
2121
manager.canvas.draw()
2222
return gtk.TRUE
2323

examples/embedding_in_gtk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
vbox.show()
2121

2222
f = Figure(figsize=(5,4), dpi=100)
23-
a = Subplot(f, 111)
23+
a = f.add_subplot(111)
2424
t = arange(0.0,3.0,0.01)
2525
s = sin(2*pi*t)
2626

2727
a.plot(t,s)
28-
f.add_axis(a)
28+
2929

3030
canvas = FigureCanvasGTK(f) # a gtk.DrawingArea
3131
canvas.show()

examples/embedding_in_gtk2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
vbox.show()
2020

2121
fig = Figure(figsize=(5,4), dpi=100)
22-
ax = Subplot(fig, 111)
22+
ax = fig.add_subplot(111)
2323
t = arange(0.0,3.0,0.01)
2424
s = sin(2*pi*t)
2525

2626
ax.plot(t,s)
27-
fig.add_axis(ax)
27+
2828

2929
canvas = FigureCanvasGTK(fig) # a gtk.DrawingArea
3030
canvas.show()

examples/embedding_in_tk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ def destroy(e): sys.exit()
1818

1919

2020
f = Figure(figsize=(5,4), dpi=100)
21-
a = Subplot(f, 111)
21+
a = f.add_subplot(111)
2222
t = arange(0.0,3.0,0.01)
2323
s = sin(2*pi*t)
2424

2525
a.plot(t,s)
26-
f.add_axis(a)
26+
2727

2828
# a tk.DrawingArea
2929
canvas = FigureCanvasTkAgg(f, master=root)

examples/histogram_demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
ylabel('Probability')
1717
title(r'$\rm{Histogram of IQ: }\mu=100, \sigma=15$')
1818
axis([40, 160, 0, 0.03])
19+
grid(True)
1920
#set(gca(), 'xlim', [40, 160])
2021
#savefig('histogram_demo',dpi=72)
2122
show()

0 commit comments

Comments
 (0)