How to plot timeline branches graphs in Python
1 answer
You just need to plot all your data using matplotlib
so that each next list starts where the first one ends in the next year, here's an example:
import datetime import matplotlib.pyplot as plt import numpy as np x = np.array([datetime.datetime(i, 1, 1) for i in range(2012,2018)]) y = np.array([1,10,14,23,22,15]) x2 = np.array([datetime.datetime(i, 1, 1) for i in range(2013,2018)]) y2 = np.array([10,54,39,62,45]) x3 = np.array([datetime.datetime(i, 1, 1) for i in range(2014,2018)]) y3 = np.array([14,43,27,65]) x4 = np.array([datetime.datetime(i, 1, 1) for i in range(2015,2018)]) y4 = np.array([23,39,85]) plt.plot(x,y) plt.plot(x2,y2) plt.plot(x3,y3) plt.plot(x4,y4) plt.tight_layout() fig = plt.gcf() fig.show()
A note y2
starts with y[1]
, y3
starts with y[2]
, etc. Also note that x
, x2
... are gradually changing, to get started in a given year.
+3
source to share