python - plot values from bidemensionnal arrays -


i have got bidimensionnal array containing values plot on y axis, , bidimensionnal array, of datetime values plot in x axis, , 2 lines of values against date arrays. these structures used as-is don't work expected, have got different kind of graph line graph.

values x axis (dates):

    [[datetime.datetime(2011, 1, 1, 0, 0, 25, 135000), datetime.datetime(2011, 2, 1, 0, 0, 57, 386000),  datetime.datetime(2011, 3, 1, 0, 0, 59, 579000), datetime.datetime(2011, 4, 1, 0, 0, 27, 676000),  datetime.datetime(2011, 5, 1, 0, 0, 25, 135000), datetime.datetime(2011, 6, 1, 0, 0, 26, 414000),  datetime.datetime(2011, 7, 1, 0, 0, 28, 145000), datetime.datetime(2011, 8, 1, 0, 0, 26, 432000),  datetime.datetime(2011, 9, 1, 0, 0, 27, 301000), datetime.datetime(2011, 10, 1, 0, 0, 27, 643000),  datetime.datetime(2011, 11, 1, 0, 0, 27, 673000), datetime.datetime(2011, 12, 1, 0, 0, 28, 294000)],  [datetime.datetime(2011, 1, 1, 0, 0, 25, 135000), datetime.datetime(2011, 2, 1, 0, 0, 57, 386000),  datetime.datetime(2011, 3, 1, 0, 0, 59, 579000), datetime.datetime(2011, 4, 1, 0, 0, 27, 676000),  datetime.datetime(2011, 5, 1, 0, 0, 25, 135000), datetime.datetime(2011, 6, 1, 0, 0, 26, 414000),  datetime.datetime(2011, 7, 1, 0, 0, 28, 145000), datetime.datetime(2011, 8, 1, 0, 0, 26, 432000),  datetime.datetime(2011, 9, 1, 0, 0, 27, 301000), datetime.datetime(2011, 10, 1, 0, 0, 27, 643000),  datetime.datetime(2011, 11, 1, 0, 0, 27, 673000), datetime.datetime(2011, 12, 1, 0, 0, 28, 294000)]] 

values y axis (min, max):

    [[-8.0, 19.0, 11.0, 6.0, 6.0, 6.0, 6.0, 6.0, 2.0, 2.0, 2.0, 2.0],  [-12.0, -7.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -7.0, -7.0]] 

i on how transform these structures 2 lines of min , max on date displayed.

if have 2 "bidimensional" arrays, called x , y, have same length, try

import numpy np import matplotlib.pyplot plt  # populate x , y arrays.  x = np.array(x) y = np.array(y)  fig = plt.figure() ax = fig.add_subplot(111)  ax.plot(x[:,0], y[:,0], 'g-o') ax.plot(x[:,1], y[:,1], 'r-x') 

in general, if arrays have 1 dimension, do

ax.plot(x, y) 

if arrays have more 2 sets of values, do

for in range(x.shape[-1]):     ax.plot(x[:,i], y[:,0]) 

the notation x[:,n] has 2 parts; : means take data every row , ,n means take n+1 (0 represents first) element each row. works because data structured like

[[date00, date01],  [date10, date11],  [date20, date21],  ...  [daten0, daten1]] 

so x[:,0] takes first column , x[:,1] takes second column.

if had large array of many dimensions, can index each array x[dim0, dim1, ..., dimn]. example, had 3 dimensional array of medical data dimensions represented patientid, sampleid, viral_load, grab last viral load number samples first patient doing data[0, :, -1], or viral load numbers samples patient doing data[0, :, :].


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -