So I've seen a few answers on here that helped a bit, but my dataset is larger than the ones that have been answered previously. To give a sense of what I'm working with, here's a link to the full dataset. I imported this into a jupyter notebook using pandas. I've included a picture of one attempted solution, which was found at this link, right here: Example Picture. 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, such as this one: It's basically unreadable. Here's the code I used to produce both of these (I just modified the included code in order to change which section of the overall dataset was used).

event = Xia['EnglishName']
begin = Xia['Start']
end = Xia['Finish']
length = Xia['Length']

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)
for i in range(18):
    plt.text(begin.iloc[i] + length.iloc[i]/2, i+.25, event.iloc[i], ha='center', fontsize = '12') 

This code semi-works, but I'd prefer if the bars were either closer together or differently colored and all on the same y-value. I appreciate any and all help. I've been trying to figure this out for about two weeks now and am hitting a brick wall.

  • $\begingroup$ Is there a chance that two bars overlap. If yes, how do you manage to have a flat y value. $\endgroup$ Jun 16, 2018 at 2:11
  • $\begingroup$ They do overlap sometimes (at one particular value, e.g. ruler 1 ends at year 50 and ruler 2 begins at year 50) but I would be more than happy to just massage the data to make it begin + x and end - x (where x is a very small value). $\endgroup$
    – Baxter
    Jun 16, 2018 at 3:50

1 Answer 1


Sorry for the late reply. I don't know whether the below kind of plot suffices for what you are looking. plot

If yes is the case, you might like matplotlib.hlines. I am providing a sample code for generating a picture like the above.

import matplotlib.pyplot as plt
import random

for x in range(0, 10, 2):
    color = random.choice(['red', 'green', 'blue', 'yellow'])
    plt.hlines(1, x, x + 2, colors=color, lw=5)
    plt.text(x + 1, 1.01, color, ha='center')

Let me know if this was helpful!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.