如何在 Matplotlib 中将线条颜色设置为橙色并指定线条标记?

matplotlibpythondata visualization更新于 2024/2/28 9:48:17

要将线条颜色设置为橙色并在 matplotlib 中指定线条标记,我们可以采取以下步骤 −

步骤

  • 设置图形大小并调整子图之间和周围的填充。

  • 使用 numpy 创建 x 和 y 数据点。

  • 使用属性 color='orange' 和 ma​​rker='*' 绘制 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

# x 和 y 数据点
x = np.linspace(-5, 5, 100)
y = np.sin(x)

# 使用颜色和标记属性绘制数据点
plt.plot(x, y, color='orange', marker="*")

# 显示绘图
plt.show()

输出

它将产生以下输出 −


相关文章


有用资源