【问题标题】:How to show more numbers on the X-Axis of a graph?如何在图表的 X 轴上显示更多数字?
【发布时间】:2013-09-26 22:35:33
【问题描述】:

(免责声明:我学习 python/编程不到一周)

这是专门针对 Python 的。我正在使用 scipy 库:Numpy 和 MatPlotLib。

如您所见,X 轴仅每 50 个单位显示一次。我希望它显示每 10 个单位的数字。

我该如何更改?

我的代码的输出:

我生成图表的代码:

x1 = []
y1 = []
x2 = []
y2 = []
x3 = []
y3 = []

def ShowMyGraph():
    plot1, = pl.plot(x1,y1,'r.')
    plot2, = pl.plot(x2,y2,'b_')
    plot3, = pl.plot(x3,y3,'-')

    pl.title('Random Encounter Pattern')
    pl.xlabel('StepID')
    pl.ylabel('Danger Value')

    pl.xlim(0.0,200.0)
    pl.ylim(0.0,8000)

    pl.legend([plot1,plot2], ('Steps', 'Battles'), 'best', numpoints=1)
    pl.show()

def PlotSteps():
    x1.append(stepid)
    y1.append(danger)
    x2.append(stepid)
    y2.append(dlimit)
    x3.append(stepid)
    y3.append(dlimit)

def dosomething():
     PlotSteps()

ShowMyGraph()

【问题讨论】:

    标签: python graph scipy


    【解决方案1】:

    pyplot.xticks() 是你想要的。

    要让 x 轴以您正在寻找的方式工作,这样的事情应该可以解决问题:

    from numpy import arange
    
    ...
    
    def ShowMyGraph():
    
    ...
    
        pl.xticks(arange(201, step=50))  # 201 since you want 200 displayed in the graph.
        pl.show()
    

    【讨论】:

      猜你喜欢
      • 2013-05-18
      • 2020-10-31
      • 2021-06-08
      • 1970-01-01
      • 2014-02-13
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多