Matplotlib 标签重叠,因为数据太多

问题描述 投票:0回答:1

这是我在jupyter笔记本中用python语言编写的代码。 垂直方向有距离,水平方向有时间。 当数据泛滥(太多)时,水平标签会相互重叠。你根本看不懂标签。我怎样才能拥有像框架的动态宽度之类的东西?或者也许其他解决方案非常受欢迎。谢谢你

    #this code below is to append the data
    if i==0:
        time = [timetable[i][0]]
    else:
        time.append(timetable[i][0])
    if timetable[i][1][:-2].lower() == 'driver':
        distances.append(0)
    elif timetable[i][1][:-2].lower() == 'rider':
        distances.append(rider_request)
    print(time, len(time))
    print(distances, len(distances))

    #dataframe for plot graph
    df=pd.DataFrame({'x': time, 'y': distances })

    # plot
    plt.plot( 'x', 'y', data=df, linestyle='-', marker='o')
    plt.show()

Graph Plot

python matplotlib graph jupyter-notebook
1个回答
0
投票

您可以在 x 轴上旋转标签来修复重叠。

ax=plt.gca()    
for item in ax.xaxis.get_ticklabels():
    item.set_rotation(+45)
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.