[英]How to truncate very long tick labels on y-axis of subplots and fit plot and labels neatly in one fig using matplotlib?
[英]How to prevent overrunning of y -axis tick labels in matplotlib plot?
大家好,我正在尝试从一个 csv 文件中绘制一个图表,其中包括许多专门针对 y 轴的唯一值(接近 500 个值)。当绘制图表时,y 轴刻度标签相互运行,我希望每个值都存在在 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()
您正在寻找更改滴答频率。 您可以通过调用轻松做到这一点
plt.xticks(np.arange(0, len(x)+1, 5))
plt.yticks(np.arange(0, max(y), 2))
你可以在这里看到很好的例子: Change Tick Frequency in Matplotlib
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.