这里是复制原始图的代码,类似这样的东西在问题中是预期的,这样可以让更多的时间来回答问题(而不是重新创建它)。在import pandas as pd
import matplotlib.pyplot as plt
xia = pd.DataFrame([['Da Yu', -2207, -2197],
['Qi', -2197, -2188],
['Tai Kang', -2188, -2159]],
columns=['EnglishName', 'Start', 'Finish'])
event = xia['EnglishName']
begin = xia['Start']
end = xia['Finish']
length = xia['Finish'] - xia['Start']
plt.figure(figsize=(12,6))
plt.barh(range(len(begin)), (end-begin), .3, left=begin)
plt.tick_params(axis='both', which='major', labelsize=15)
plt.tick_params(axis='both', which='minor', labelsize=20)
plt.title('Xia Dynasty', fontsize = '25')
plt.xlabel('Year', fontsize = '20')
plt.yticks(range(len(begin)), "")
plt.xlim(-2250, -1750)
plt.ylim(-1,18)
for i in range(3):
plt.text(begin.iloc[i] + length.iloc[i]/2,
i+.25, event.iloc[i],
ha='center', fontsize = '12')
申诉(解决下一步要做什么):The issue is that
1. This is difficult to read and
2. I don't know how to flatten it out so that it looks like a traditional timeline. The issue becomes more apparent when I try and work with larger segments
I'd prefer if the bars were either closer together or differently colored and all on the same y-value.
这些设计很难用语言来说明。如果你放在一行(例如用这个plt.barh([1 for _ in begin], (end-begin)-0.5, .3, left=begin)),文本的重叠将更加不可读。在
下面是一个小代码来重现水平时间线:
^{pr2}$
但是你想把名字放在哪里呢?在
如果你想要不同的颜色,需要一些关于颜色的规则。程序员会说你需要一个更好的任务规范。在