Graphing arrays with different lengths on the same Pandas graph

You can pad the arrays to same size with filling small array to zero or none : use this snippet to make it :

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import datetime

a = np.array(['2017-09-15 07:11:00', '2017-09-15 12:11:00', '2017-12-22 06:35:00'], dtype='datetime64[ns]')
b = np.array(['2017-09-10 02:25:00', '2017-12-11 03:11:00'], dtype='datetime64[ns]')


m = max(len(s1),len(s2))
a1=[None] * m
a2=[None] * m
ax1=[None] * m
ax2=[None] * m

for i in range(len(s1)):
    a1[i] = s1[i]
for i in range(len(s2)):
    a2[i] = s2[i]

graph= pd.DataFrame({
   'A Values': np.array(a1),
   'B Values': np.array(a2)
   }, index= [ax1,ax2]).plot.line()
plt.tick_params(axis='both', which='major', labelsize=5) 
#labelsize=5 instead of labelsize=10


enter image description here

I hope you find it useful

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top