如何使用 Matplotlib 更改绘图的面部颜色?
要使用 matplotlib 更改绘图的面部颜色,我们可以采取以下步骤:-
- 设置图形大小并调整各子图之间和周围的内边距。
- 使用 numpy 创建 x 和 y 数据点。
- 创建一个图形和一组子图。
- 使用 color=yellow 和 linewidth=7 的 plot() 方法绘制 x 和 y 数据点。
- 使用 set_facecolor() 设置坐标轴的面部颜色。
- 要显示图形,请使用 show() 方法。
范例
from matplotlib import pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create x and y data points x = np.linspace(-10, 10, 100) y = np.sin(x) # Create a figure and set of subplots fig, ax = plt.subplots() # Plot the x and y data points with color ax.plot(x, y, color='yellow', lw=7) # Set the facecolor ax.set_facecolor('red') plt.show()
输出
它将生成以下输出
广告