简体   繁体   English

如何让 matplotlib.pyplot 沿 Y 轴标记每隔几个标签?

[英]How do I get matplotlib.pyplot to label every few labels down the Y-Axis?

I'm attempting to plot data from a .csv file and I want it to put less values down the Y-axis.我正在尝试从 .csv 文件中绘制数据,并且我希望它在 Y 轴上放置更少的值。

This is the output I am getting at the moment:这是我目前得到的输出:这个

I would also like the numbers to be automatically rounded or neatened up to make the plot more readable.我还希望将数字自动四舍五入或整理,以使情节更具可读性。

def GraphBuilder():
    item = 0
    savenumber = 1
    ColumnTime = itemgetter(0)(column_names)
    while item < col_count:
        SecondaryColumn = itemgetter(item)(column_names)
        ColumnTimeData = pandagraph[ColumnTime]
        SecondaryColumnData = pandagraph[(SecondaryColumn)]
        plt.xlim([0, 1000])
        plt.ylim([-100, 100000])
        plt.ylabel(SecondaryColumn)
        plt.plot(ColumnTimeData, SecondaryColumnData)
        plt.xticks(rotation = 45)
        print("Starting new graph")
        Start = 0
        End = 0
        Start = time.time()
        plt.savefig(f"Graph{savenumber}.tiff")
        plt.close()
        plt.cla()
        plt.clf()
        print(f"Graph {savenumber} completed")
        End = time.time()
        TotalGraphTime = End - Start
        TotalGraphTime = round(TotalGraphTime, 2)
        print("Graph completed in: ", TotalGraphTime, " Seconds.")
        time.sleep(0.1)
        item += 1
        savenumber +=1 

I'm not sure how to make the program do this so any help is greatly appreciated.我不确定如何使程序执行此操作,因此非常感谢任何帮助。

要更改刻度数,我建议查看 plt.yticks

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM