如何防止Matplotlib图中的Y轴tick标签超过?

发布于 2025-02-11 18:28:32 字数 1476 浏览 0 评论 0原文

“

嗨,我想从CSV文件中绘制图形,该图形包括许多独特的值500值)。绘制图形时,y轴tick标签互相运行,我希望每个值都存在于y轴上。我不想跳过值。任何人都可以建议我如何使我的图形在整齐地读取y轴上的所有这500个值。

 fig, ax = plt.subplots()
    #plt.figure(figsize=(800/my_dpi, 800/my_dpi), dpi=my_dpi)
    plt.rcParams["figure.figsize"] = [7.00, 5.50]
    plt.rcParams["figure.autolayout"] = True
    space = 3
    dash_len = 3
    ax.set_facecolor("yellow")
    ax.plot(sorted(failed_it),failed_p,color='r',linestyle='dashed',dashes=(dash_len, 
    space),alpha=0.7, linewidth = 1,marker='s', markerfacecolor='red', markersize=4)
    ax.plot(sorted(passed_it),passed_p,color='g',linestyle='dashed',dashes=(dash_len, 
    space),alpha=0.7, linewidth = 1,marker='d', markerfacecolor='blue', markersize=4)
    plt.style.use('fivethirtyeight')
    plt.xlabel("Iteration_Rate",fontweight="bold",fontsize=9)
    plt.ylabel("Trigger_Port,VLAN",fontweight="bold")
    plt.title("Platform="+str(keyss[3])+",Build="+ str(list1_8112[0][1])+",Trigger- 
    SystemRestart",fontweight="bold")
    size = fig.get_size_inches()*fig.dpi
    print(size)
    ax = plt.gca()
    ax.set_xticks(np.arange(0,6,1))
    ax.xaxis.set_label_coords(1.07, -0.025)
    ax.xaxis.set_major_locator(plt.MaxNLocator(100))
`   plt.yticks(port_VLAN_8112,ha='right',fontsize=8)
    plt.xticks(it_rate_8112[::20],ha='right',fontsize=8)
    plt.margins(0)
    ax.grid('on')
    plt.show()
    fig = plt.figure()

1

Hi everyone i am trying to plot a graph from a csv file which includes many unique values specially for y axis(close to 500 values).When graph is plotted y axis tick labels are over running each other and i want each values to be present on y-axis .I dont want to skip values. Can anyone suggest me how can i make my graph having all these 500 values on y-axis read neatly.

 fig, ax = plt.subplots()
    #plt.figure(figsize=(800/my_dpi, 800/my_dpi), dpi=my_dpi)
    plt.rcParams["figure.figsize"] = [7.00, 5.50]
    plt.rcParams["figure.autolayout"] = True
    space = 3
    dash_len = 3
    ax.set_facecolor("yellow")
    ax.plot(sorted(failed_it),failed_p,color='r',linestyle='dashed',dashes=(dash_len, 
    space),alpha=0.7, linewidth = 1,marker='s', markerfacecolor='red', markersize=4)
    ax.plot(sorted(passed_it),passed_p,color='g',linestyle='dashed',dashes=(dash_len, 
    space),alpha=0.7, linewidth = 1,marker='d', markerfacecolor='blue', markersize=4)
    plt.style.use('fivethirtyeight')
    plt.xlabel("Iteration_Rate",fontweight="bold",fontsize=9)
    plt.ylabel("Trigger_Port,VLAN",fontweight="bold")
    plt.title("Platform="+str(keyss[3])+",Build="+ str(list1_8112[0][1])+",Trigger- 
    SystemRestart",fontweight="bold")
    size = fig.get_size_inches()*fig.dpi
    print(size)
    ax = plt.gca()
    ax.set_xticks(np.arange(0,6,1))
    ax.xaxis.set_label_coords(1.07, -0.025)
    ax.xaxis.set_major_locator(plt.MaxNLocator(100))
`   plt.yticks(port_VLAN_8112,ha='right',fontsize=8)
    plt.xticks(it_rate_8112[::20],ha='right',fontsize=8)
    plt.margins(0)
    ax.grid('on')
    plt.show()
    fig = plt.figure()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我最亲爱的 2025-02-18 18:28:32

您正在寻找更改tick频率。
您可以通过打电话来轻松执行此操作,

plt.xticks(np.arange(0, len(x)+1, 5))
plt.yticks(np.arange(0, max(y), 2))

您可以在此处看到很棒的示例:更改matplotlib中的tick频率

You are looking for changing the ticks frequency.
You can easily do that by calling

plt.xticks(np.arange(0, len(x)+1, 5))
plt.yticks(np.arange(0, max(y), 2))

You can see great examples here: Change Tick Frequency in Matplotlib

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文