📌  相关文章
📜  Python中的 Matplotlib.axes.Axes.set_rasterized()

📅  最后修改于: 2022-05-13 01:55:41.222000             🧑  作者: Mango

Python中的 Matplotlib.axes.Axes.set_rasterized()

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。

matplotlib.axes.Axes.set_rasterized()函数

matplotlib 库的轴模块中的Axes.set_rasterized()函数用于强制在矢量后端输出中进行光栅化(位图)绘图。

下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.set_rasterized()函数:

示例 1:

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
   
  
d = np.arange(100).reshape(10, 10)
xx, yy = np.meshgrid(np.arange(11), np.arange(11))
   
fig, ax = plt.subplots()
   
ax.set_aspect(1)
m = ax.pcolormesh(xx, yy, d)
m.set_rasterized(True)
  
fig.suptitle('matplotlib.axes.Axes.set_rasterized() \
function Example', fontweight ="bold")
  
plt.show()

输出:

示例 2:

# Implementation of matplotlib function
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.gridspec as gridspec
import numpy as np
   
   
arr = np.arange(100).reshape((10, 10))
norm = mcolors.Normalize(vmin = 0., vmax = 100.)
   
pc_kwargs = {'cmap': 'plasma', 'norm': norm}
   
fig, ax = plt.subplots( )
   
im = ax.pcolormesh(arr, **pc_kwargs)
fig.colorbar(im, ax = ax, shrink = 0.6)
   
ax.set_rasterized(False)
  
fig.suptitle('matplotlib.axes.Axes.set_rasterized()\
 function Example', fontweight ="bold")
  
plt.show()

输出: