Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to set propee timeline in python

event = data_set_adj['EnglishName']
begin = data_set_adj['Start']
end = data_set_adj['Finish']
length =  data_set_adj['Length']
dynasty = data_set_adj['Dynasty']
dynasty_col = data_set_adj['Dynasty_col']

dict_dynasty = dict(zip(dynasty.unique(), range(0,4*len(dynasty.unique()),4)))

levels = np.tile([-1.2,1.2, -0.8, 0.8, -0.4, 0.4],
                 int(np.ceil(len(begin)/6)))[:len(begin)]

import matplotlib.pyplot as plt
plt.style.use('ggplot')
plt.figure(figsize=(20,10))

for x in range(len(dynasty)):   
    plt.vlines(begin.iloc[x]+length.iloc[x]/2, dict_dynasty[dynasty.iloc[x]], dict_dynasty[dynasty.iloc[x]]+levels[x], color="tab:red")
    plt.barh(dict_dynasty[dynasty.iloc[x]], (end.iloc[x]-begin.iloc[x]), color=dynasty_col.iloc[x], height =0.3 ,left=begin.iloc[x], edgecolor = "black", alpha = 0.5)
    if x%2==0:
        plt.text(begin.iloc[x] + length.iloc[x]/2, 
                 dict_dynasty[dynasty.iloc[x]]+1.6*levels[x], event.iloc[x], 
                 ha='center', fontsize = '8')
    else:
        plt.text(begin.iloc[x] + length.iloc[x]/2, 
                 dict_dynasty[dynasty.iloc[x]]+1.25*levels[x], event.iloc[x], 
                 ha='center', fontsize = '8')
plt.tick_params(axis='both', which='major', labelsize=15)
plt.tick_params(axis='both', which='minor', labelsize=20)
plt.title('Chinese Dynasties', fontsize = '25')
plt.xlabel('Year', fontsize = '20')
ax = plt.gca()
ax.axes.yaxis.set_visible(False)
plt.xlim(900, 1915)
plt.ylim(-4,28)


plt.tight_layout()
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: getting python class from string 
Python :: logging python 
Python :: how to iterate a list in reverse order in python with index 
Python :: python book 
Python :: how to run mac terminal from python script 
Python :: websocket api python on close 
Python :: {} string python 
Python :: Examples of os.makedirs() method 
Python :: remove deprecation warning python 
Python :: sort dictionary by key python 
Python :: create a date value array in python 
Python :: python class set dict method 
Python :: beautiful soup find 
Python :: Swap 2 items of a list in python 
Python :: ImportError: sys.meta_path is None, Python is likely shutting down 
Python :: if-else Conditional Statement in Python 
Python :: np.random.randint to generate -1 +1 
Python :: python dictionary with dot notation 
Python :: python cant remove temporary files 
Python :: Python DateTime Time Class Example 
Python :: python observer pattern 
Python :: how to use a class in python 
Python :: cascade models in django 
Python :: true and false in python 
Python :: shape 
Python :: assign multiple columns pandas 
Python :: how to split from a specific charecter to the end of the string in python 
Python :: python linter online 
Python :: python referenced before assignment in function 
Python :: Renaming and replacing the column variable name 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =