首页 > 解决方案 > Matplotlib 标签重叠,因为数据太多

问题描述

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

    #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()

图表

标签: pythonmatplotlibgraphjupyter-notebook

解决方案


推荐阅读