如何在 Python 3 中为 matplotlib 2.0 的 ‘ax’ 对象添加黑色边框?
要在 Python 中为 matplotlib 2.0 的 ‘ax’ 对象添加黑色边框,可以执行以下步骤—
- 设置图形的大小并调整子图之间和周围的填充。
- 将轴边缘颜色设置为黑色。
- 将轴线宽度设置为 2.50。
- 初始化变量 N 以获取样本数据的数量。
- 使用 numpy 创建 x 和 y 数据点。
- 使用 plot() 方法绘制 x 和 y 数据点。
- 使用 show() 方法来显示图形。
示例
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.rcParams["axes.edgecolor"] = "black"
plt.rcParams["axes.linewidth"] = 2.50
N = 10
x = np.random.randint(low=0, high=N, size=N)
y = np.random.randint(low=0, high=N, size=N)
plt.plot(x, y, color='red')
plt.show()