Draw line chart from two arrays

Hi I want to draw a line chart with two arrays' data.

ArrayA 
array([265266., 248146., 262715., 280663., 238083., 270262., 254179.,
       277202., 306039., 281294., 294978., 304122., 351522., 340181.,
       322776., 327759., 310442., 328161., 313920., 355952., 344338.,
       322330., 345088., 365234., 420498.])

ArrayB
array([ 26526,  24814,  26271,  28066,  23808,  27026,  25417,  27720,
        30603,  28129,  29497,  30412,  35152,  34018,  32277,  32775,
        31044,  32816,  31392,  35595,  86084, 112815, 172544, 219140,
       420498])

The two arrays are in the same shape. I would like to draw them on one line chart. I tried

import matplotlib.pyplot as plt
plt.plot(diagonal,[25000,400000],'r--',df2array, [10000,425000], 'bs')
plt.show()

I'm not sure the second parameter [25000,400000], is it for specifying the range of my array ?

I received error x and y must have same first dimension, but have shapes (25,) and (2,) However, the arrays are in the same shape.

1 answer

  • answered 2019-01-22 02:08 Klaus Jude

    The second parameter is for your y-axis value. If what you're trying to do is to plot df2array against diagonal then you should try

    plt.plot(diagonal, df2array)
    

    (That is if they are of the same size) For specifying range you use python slicing and indexing