如何在 Matplotlib Python 中绘制单个点?


若要在 matplotlib 中绘制单个数据点,可执行以下步骤 -

  • 使用单个值初始化 x 和 y 的列表。

  • 限制 X 和 Y 轴范围为 0 到 5。

  • 在当前行样式中布局网格。

  • 使用 plot() 方法绘制 x 和 y,并使用 marker="o", markeredgecolor="red", markerfacecolor="green"

  • 要显示图形,请使用 show() 方法。

示例

from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x = [4]
y = [3]
plt.xlim(0, 5)
plt.ylim(0, 5)
plt.grid()
plt.plot(x, y, marker="o", markersize=20, markeredgecolor="red", markerfacecolor="green")
plt.show()

输出

更新于: 23-Aug-2023

65K+ 浏览量

开启您的 职业生涯

完成课程即可获得认证

立即开始
广告
© . All rights reserved.