0

I have two 2D arrays (lat,lon), both derived from the same netcdf (.nc) file. Both the arrays have the same shape. My aim is to make a line plot with these two arrays. I expect it to be a simple curve with one line but am getting multiple lines. I am very confused. What is the obvious error in my code?

#shape of arrays:
#array 1= (96, 192)
#array 2= (96, 192)

x=array1
y=array2

plt.plot(x[:],y[:])

enter image description here

  • 1
    Flatten both arrays (`x.flat`), then [sort both arrays for x-values](https://stackoverflow.com/a/1903579/8881141). Matplotlib interprets each row of your arrays as a different category (hence, the different colors) and plots values as they come (hence, some curves go back along the x-axis). – Mr. T Feb 15 '22 at 11:17
  • Thank you very much! It worked! – Learning_datascience Feb 15 '22 at 11:26

0 Answers0