这是我在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()
您可以在 x 轴上旋转标签来修复重叠。
ax=plt.gca()
for item in ax.xaxis.get_ticklabels():
item.set_rotation(+45)