Changes for 0.98.0¶
matplotlib.image.imread()
now no longer always returns RGBA data---if the image is luminance or RGB, it will return a MxN or MxNx3 array if possible. Also uint8 is no longer always forced to float.- Rewrote the
matplotlib.cm.ScalarMappable
callback infrastructure to usematplotlib.cbook.CallbackRegistry
rather than custom callback handling. Any users ofmatplotlib.cm.ScalarMappable.add_observer
of theScalarMappable
should use thematplotlib.cm.ScalarMappable.callbacksSM
CallbackRegistry
instead. - New axes function and Axes method provide control over the plot
color cycle:
matplotlib.axes.set_default_color_cycle
andmatplotlib.axes.Axes.set_color_cycle
. - Matplotlib now requires Python 2.4, so
matplotlib.cbook
will no longer provideset
,enumerate()
,reversed()
orizip
compatibility functions. - In Numpy 1.0, bins are specified by the left edges only. The axes
method
matplotlib.axes.Axes.hist()
now uses future Numpy 1.3 semantics for histograms. Providingbinedges
, the last value gives the upper-right edge now, which was implicitly set to +infinity in Numpy 1.0. This also means that the last bin doesn't contain upper outliers any more by default. - New axes method and pyplot function,
hexbin()
, is an alternative toscatter()
for large datasets. It makes something like apcolor()
of a 2-D histogram, but uses hexagonal bins. - New kwarg,
symmetric
, inmatplotlib.ticker.MaxNLocator
allows one require an axis to be centered around zero. - Toolkits must now be imported from
mpl_toolkits
(notmatplotlib.toolkits
)
Notes about the transforms refactoring¶
A major new feature of the 0.98 series is a more flexible and extensible transformation infrastructure, written in Python/Numpy rather than a custom C extension.
The primary goal of this refactoring was to make it easier to extend matplotlib to support new kinds of projections. This is mostly an internal improvement, and the possible user-visible changes it allows are yet to come.
See matplotlib.transforms
for a description of the design of
the new transformation framework.
For efficiency, many of these functions return views into Numpy arrays. This means that if you hold on to a reference to them, their contents may change. If you want to store a snapshot of their current values, use the Numpy array method copy().
The view intervals are now stored only in one place -- in the
matplotlib.axes.Axes
instance, not in the locator instances
as well. This means locators must get their limits from their
matplotlib.axis.Axis
, which in turn looks up its limits from
the Axes
. If a locator is used temporarily
and not assigned to an Axis or Axes, (e.g., in
matplotlib.contour
), a dummy axis must be created to store its
bounds. Call matplotlib.ticker.TickHelper.create_dummy_axis()
to
do so.
The functionality of Pbox
has been merged with
Bbox
. Its methods now all return
copies rather than modifying in place.
The following lists many of the simple changes necessary to update code from the old transformation framework to the new one. In particular, methods that return a copy are named with a verb in the past tense, whereas methods that alter an object in place are named with a verb in the present tense.
matplotlib.transforms
¶
Old method | New method |
---|---|
Bbox.get_bounds |
transforms.Bbox.bounds |
Bbox.width |
transforms.Bbox.width |
Bbox.height |
transforms.Bbox.height |
Bbox.intervalx().get_bounds()
Bbox.intervalx().set_bounds() |
transforms.Bbox.intervalx
[It is now a property.] |
Bbox.intervaly().get_bounds()
Bbox.intervaly().set_bounds() |
transforms.Bbox.intervaly
[It is now a property.] |
Bbox.xmin |
transforms.Bbox.x0 or
transforms.Bbox.xmin [1] |
Bbox.ymin |
transforms.Bbox.y0 or
transforms.Bbox.ymin [1] |
Bbox.xmax |
transforms.Bbox.x1 or
transforms.Bbox.xmax [1] |
Bbox.ymax |
transforms.Bbox.y1 or
transforms.Bbox.ymax [1] |
Bbox.overlaps(bboxes) |
Bbox.count_overlaps(bboxes) |
bbox_all(bboxes) |
Bbox.union(bboxes)
[It is a staticmethod.] |
lbwh_to_bbox(l, b, w, h) |
Bbox.from_bounds(x0, y0, w, h)
[It is a staticmethod.] |
inverse_transform_bbox(trans, bbox) |
Bbox.inverse_transformed(trans) |
Interval.contains_open(v) |
interval_contains_open(tuple, v) |
Interval.contains(v) |
interval_contains(tuple, v) |
identity_transform() |
transforms.IdentityTransform |
blend_xy_sep_transform(xtrans, ytrans) |
blended_transform_factory(xtrans, ytrans) |
scale_transform(xs, ys) |
Affine2D().scale(xs[, ys]) |
get_bbox_transform(boxin, boxout) |
BboxTransform(boxin, boxout) or
BboxTransformFrom(boxin) or
BboxTransformTo(boxout) |
Transform.seq_xy_tup(points) |
Transform.transform(points) |
Transform.inverse_xy_tup(points) |
Transform.inverted() .transform(points) |
[1] | (1, 2, 3, 4) The Bbox is bound by the points
(x0, y0) to (x1, y1) and there is no defined order to these points,
that is, x0 is not necessarily the left edge of the box. To get
the left edge of the Bbox , use the read-only property
xmin . |
matplotlib.axes
¶
Old method | New method |
---|---|
Axes.get_position() |
matplotlib.axes.Axes.get_position() [2] |
Axes.set_position() |
matplotlib.axes.Axes.set_position() [3] |
Axes.toggle_log_lineary() |
matplotlib.axes.Axes.set_yscale() [4] |
Subplot class |
removed |
The Polar
class has moved to matplotlib.projections.polar
.
[2] | matplotlib.axes.Axes.get_position() used to return a list
of points, now it returns a matplotlib.transforms.Bbox
instance. |
[3] | matplotlib.axes.Axes.set_position() now accepts either
four scalars or a matplotlib.transforms.Bbox instance. |
[4] | Since the recfactoring allows for more than two scale types
('log' or 'linear'), it no longer makes sense to have a toggle.
Axes.toggle_log_lineary() has been removed. |
matplotlib.artist
¶
Old method | New method |
---|---|
Artist.set_clip_path(path) |
Artist.set_clip_path(path, transform) [5] |
[5] | matplotlib.artist.Artist.set_clip_path() now accepts a
matplotlib.path.Path instance and a
matplotlib.transforms.Transform that will be applied to
the path immediately before clipping. |
matplotlib.collections
¶
Old method | New method |
---|---|
linestyle | linestyles [6] |
[6] | Linestyles are now treated like all other collection attributes, i.e. a single value or multiple values may be provided. |
matplotlib.colors
¶
Old method | New method |
---|---|
ColorConvertor.to_rgba_list(c) |
colors.to_rgba_array(c)
[matplotlib.colors.to_rgba_array()
returns an Nx4 NumPy array of RGBA color quadruples.] |
matplotlib.contour
¶
Old method | New method |
---|---|
Contour._segments |
matplotlib.contour.Contour.get_paths [Returns a
list of matplotlib.path.Path instances.] |
matplotlib.figure
¶
Old method | New method |
---|---|
Figure.dpi.get()
Figure.dpi.set() |
matplotlib.figure.Figure.dpi
(a property) |
matplotlib.patches
¶
Old method | New method |
---|---|
Patch.get_verts() |
matplotlib.patches.Patch.get_path() [Returns a
matplotlib.path.Path instance] |
matplotlib.backend_bases
¶
Old method | New method |
---|---|
GraphicsContext.set_clip_rectangle(tuple) |
GraphicsContext.set_clip_rectangle(bbox) |
GraphicsContext.get_clip_path() |
GraphicsContext.get_clip_path() [7] |
GraphicsContext.set_clip_path() |
GraphicsContext.set_clip_path() [8] |
[7] | matplotlib.backend_bases.GraphicsContextBase.get_clip_path()
returns a tuple of the form (path, affine_transform), where path is a
matplotlib.path.Path instance and affine_transform is a
matplotlib.transforms.Affine2D instance. |
[8] | matplotlib.backend_bases.GraphicsContextBase.set_clip_path() now
only accepts a matplotlib.transforms.TransformedPath instance. |
RendererBase
¶
New methods:
draw_path(self, gc, path, transform, rgbFace)
draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace)
draw_path_collection(self, master_transform, cliprect, clippath, clippath_trans, paths, all_transforms, offsets, offsetTrans, facecolors, edgecolors, linewidths, linestyles, antialiaseds)
[optional]
Changed methods:
draw_image(self, x, y, im, bbox)
is nowdraw_image(self, x, y, im, bbox, clippath, clippath_trans)
Removed methods:
draw_arc
draw_line_collection
draw_line
draw_lines
draw_point
draw_quad_mesh
draw_poly_collection
draw_polygon
draw_rectangle
draw_regpoly_collection