【问题标题】:How to plot my data using MatPloitLib with step size如何使用具有步长的 MatPlotLib 绘制我的数据
【发布时间】:2022-01-02 14:36:29
【问题描述】:

考虑下面的代码和从中得到的图形

import matplotlib.pyplot as plt
import numpy as np
fig,axs = plt.subplots(figsize=(10,10)) 
data1 = [5, 6, 18, 7, 19]
x_ax = [10, 20, 30, 40, 50]
y_ax = [0, 5, 10, 15, 20]
axs.plot(data1,marker="o")
axs.set_xticks(x_ax)
axs.set_xticklabels(labels=x_ax,rotation=45)
axs.set_yticks(y_ax)
axs.set_yticklabels(labels=y_ax,rotation=45)
axs.set_xlabel("X")
axs.set_ylabel("Y")
axs.set_title("Name")

我需要以10 的步长绘制我的data1 = [5, 6, 18, 7, 19]。 5 代表 10,6 代表 20,18 代表 30,7 代表 40 和 19 代表 50。但情节的步长为 1。

如何修改我的代码以执行所需的操作?

【问题讨论】:

    标签: matplotlib graph


    【解决方案1】:

    如果您不向plot 提供x 值,它将自动使用0, 1, 2 ...

    所以在你的情况下你需要:

    x = range(10, len(data1)*10+1, 10)
    axs.plot(x, data1, marker="o")
    

    【讨论】:

      猜你喜欢
      • 2017-03-22
      • 1970-01-01
      • 2021-07-17
      • 2017-05-28
      • 2022-01-27
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 2019-05-31
      相关资源
      最近更新 更多