1.2.x 中的 API 更改#
- rc 参数 - toolbar的- classic选项已弃用,并将在下个版本中移除。
- matplotlib.cbook.isvector方法已被移除,因为它已不再起作用。
- 在 - Axes上的- rasterization_zorder属性设置了一个 zorder 值,低于此值的 artist 将被栅格化。此值之前默认为 -30000.0,但现在默认为 None,这意味着不会有 artist 被栅格化。为了栅格化低于给定 zorder 值的 artist,必须明确调用- set_rasterization_zorder。
- 使用 - twinx()或- twiny()不再覆盖坐标轴上当前的定位器 (locaters) 和格式化器 (formatters)。
- 在 - contourf()中,extend kwarg 的处理方式已更改。以前,扩展范围在归一化后被映射到 0 到 1 之间,因此它们始终对应于颜色映射的极值。现在它们被映射到此范围之外,以便与由- set_under()和- set_over()方法确定的特殊颜色映射值相对应,这些特殊值默认为颜色映射的端点。
- 新的 rc 参数 - savefig.format替代了- cairo.format和- savefig.extension,并设置了由- matplotlib.figure.Figure.savefig()使用的默认文件格式。
- 在 - pyplot.pie()和- axes.Axes.pie()中,现在可以设置饼图的半径;将 radius 设置为 'None'(默认值)将像以前一样生成半径为 1 的饼图。
- 使用 - matplotlib.projections.projection_factory现在已弃用,转而支持使用- matplotlib.projections.process_projection_requirements进行坐标轴类识别,然后直接调用坐标轴类(在撰写本文时,执行此操作的函数有:- add_axes()、- add_subplot()和- gca())。因此- key = figure._make_key(*args, **kwargs) ispolar = kwargs.pop('polar', False) projection = kwargs.pop('projection', None) if ispolar: if projection is not None and projection != 'polar': raise ValueError('polar and projection args are inconsistent') projection = 'polar' ax = projection_factory(projection, self, rect, **kwargs) key = self._make_key(*args, **kwargs) # is now projection_class, kwargs, key = \ process_projection_requirements(self, *args, **kwargs) ax = projection_class(self, rect, **kwargs) - 这一更改意味着第三方对象可以通过提供 - _as_mpl_axes方法,将自己暴露为 Matplotlib 坐标轴。有关更多详细信息,请参阅- matplotlib.projections。
- 在 - colorbar()和- ColorbarBase中新增了一个关键字 *extendfrac*,它允许控制颜色条上三角形最小和最大扩展的尺寸。
- 在 - errorbar()中新增了一个关键字 *capthick*,作为 *markeredgewidth* 和 *mew* 关键字参数的直观别名,它们间接控制了误差条上帽线的粗细。为了向后兼容,指定任何一个原始关键字参数都将覆盖 *capthick* 提供的值。
- 变换子类化的行为现在已发生了微妙变化。如果您的变换实现了非仿射变换,那么它应该覆盖 - transform_non_affine方法,而不是通用的- transform方法。以前,变换会定义- transform,然后将该方法复制到- transform_non_affine中。- class MyTransform(mtrans.Transform): def transform(self, xy): ... transform_non_affine = transform - 这种方法将不再正常工作,并且应该改为 - class MyTransform(mtrans.Transform): def transform_non_affine(self, xy): ... 
- Artist 不再具有 - x_isdata或- y_isdata属性;相反,任何 artist 的变换都可以通过- artist_instance.get_transform().contains_branch(ax.transData)进行查询。
- 添加到坐标轴的线现在在更新数据和视图限制时会考虑其变换。这意味着变换现在可以用作预变换。例如 - >>> import matplotlib.pyplot as plt >>> import matplotlib.transforms as mtrans >>> ax = plt.axes() >>> ax.plot(range(10), transform=mtrans.Affine2D().scale(10) + ax.transData) >>> print(ax.viewLim) Bbox('array([[ 0., 0.],\n [ 90., 90.]])') 
- 现在可以使用变换上的新 subtract 方法,以优化方式轻松获取从一个变换坐标系到另一个变换坐标系的变换。例如,要从数据坐标系转到坐标轴坐标系 - >>> import matplotlib.pyplot as plt >>> ax = plt.axes() >>> data2ax = ax.transData - ax.transAxes >>> print(ax.transData.depth, ax.transAxes.depth) 3, 1 >>> print(data2ax.depth) 2 - 对于 1.2 之前的版本,这只能通过次优方式实现,即使用 - ax.transData + ax.transAxes.inverted()(深度是一个新概念,但如果它存在,在此示例中将返回 4)。
- twinx和- twiny现在在父坐标轴是 SubplotBase 的实例时,返回 SubplotBase 的实例。
- 所有基于 Qt3 的后端现在已弃用,因为缺乏 py3k 绑定。Qt 和 QtAgg 后端将继续在 v1.2.x 中支持 py2.6 和 py2.7。预计 Qt3 支持将在下个版本中完全移除。 
- matplotlib.colors.ColorConverter、- Colormap和- Normalize现在继承自- object。
- ContourSet 实例不再具有 - transform属性。相反,请使用- get_transform方法访问变换。