简体   繁体   English

如何防止 matplotlib 图中的 y 轴刻度标签溢出?

[英]How to prevent overrunning of y -axis tick labels in matplotlib plot?

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.大家好,我正在尝试从一个 csv 文件中绘制一个图表,其中包括许多专门针对 y 轴的唯一值(接近 500 个值)。当绘制图表时,y 轴刻度标签相互运行,我希望每个值都存在在 y 轴上。我不想跳过值。 Can anyone suggest me how can i make my graph having all these 500 values on y-axis read neatly.谁能建议我如何使我的图表在 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()

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你可以在这里看到很好的例子: Change Tick Frequency in Matplotlib

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

相关问题 如何使用 matplotlib 在一个图中截断子图 y 轴上非常长的刻度标签并整齐地适合 plot 和标签? - How to truncate very long tick labels on y-axis of subplots and fit plot and labels neatly in one fig using matplotlib? 如何使用 Pandas/Matplotlib 将 plot X 轴上的日期、Y 轴上的时间和 HH:MM 格式的当前时间作为刻度标签? - How to plot Date in X Axis, Time in Y axis with Pandas/Matplotlib and present time in HH:MM format as tick labels? Matplotlib 图在 y 轴上显示 2 个标签 - Matplotlib plot shows 2 labels on the y-axis 在 matplotlib 中旋转第二个 y 轴刻度标签 - Rotating 2nd y-axis tick labels in matplotlib matplotlib 轴 label 在增加子图的 y 刻度标签时丢失 - matplotlib axis label lost when increasing y tick labels for subplot 在 Matplotlib、Python 中删除某些子图的 y 轴刻度标签 - Removing y axis tick labels for certain subplots in Matplotlib,Python 如何旋转极坐标matplotlib图中的刻度标签? - How to rotate tick labels in polar matplotlib plot? 如何更正matplotlib图中重叠的刻度标签? - How to correct overlapping tick labels in matplotlib plot? 如何在 matplotlib plot 顶部显示刻度标签? - how to show tick labels on top of matplotlib plot? 如何在 matplotlib 子图中删除除“0”之外的所有 y 轴刻度标签和标记? - How to remove all y-axis tick labels and markers except for '0' in a matplotlib subplot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM