0

I'm trying to list the data points/lines that i already plotted but i can't get it to work. I tried several things but unfortunatly without results.

What i want is that i get a list of the data points that i just plotted. After that i want to be able to create multiple lines with the help of the list instead of all tiny lines what happens now. the plotting is done in these two lines:

this one plots vertical lines ax.plot([i+1.5,i+1.5], [j+.5,j+1.5], linewidth=3,linestyle='-',color='#000000')

and this one plots horizontal lines ax.plot([i+.5,i+1.5], [j+1.5,j+1.5], linewidth=3,linestyle='-',color='#000000')

can anybody help me out? below is a part of my code.

for iIsochrone in range(int(np.nanmin(array)),int(np.nanmax(array)), Wavelinetime):
        #zorgt voor golflijn met stappen van 10 vertikaal
        for i in range(fileObject.numberOfColumnsInArray-1):
            for j in range(fileObject.numberOfRowsInArray):
                if (array[j, i]<=iIsochrone and array[j, i+1]>iIsochrone) or (array[j, i]>iIsochrone and array[j, i+1]<=iIsochrone):
                   ax.plot([i+1.5,i+1.5], [j+.5,j+1.5], linewidth=3,linestyle='-',color='#000000') #rechte blockline         
        #zorgt voor golflijn met stappen van 10 horizontaal
        for i in range(fileObject.numberOfColumnsInArray):
            for j in range(fileObject.numberOfRowsInArray-1):
                if (array[j, i]<=iIsochrone and array[j+1, i]>iIsochrone) or (array[j, i]>iIsochrone and array[j+1, i]<=iIsochrone):
                    ax.plot([i+.5,i+1.5], [j+1.5,j+1.5], linewidth=3,linestyle='-',color='#000000') #rechte blockline```
Sorsha
  • 5
  • 2

1 Answers1

0

As detailed in this SO post, you could use the get_lines() method to extract data points from your plot

gca().get_lines()[n].get_xydata()

EDIT:

Another option would be to save the values before they are being plotted.

For instance, since you are working with lists, you could save your i values to a list called mylisti and your j values to another list called mylistj:

mylisti=[]
mylistj=[]

for iIsochrone in range(int(np.nanmin(array)),int(np.nanmax(array)), Wavelinetime):
        #zorgt voor golflijn met stappen van 10 vertikaal
        for i in range(fileObject.numberOfColumnsInArray-1):
            for j in range(fileObject.numberOfRowsInArray):
                if (array[j, i]<=iIsochrone and array[j, i+1]>iIsochrone) or (array[j, i]>iIsochrone and array[j, i+1]<=iIsochrone):
                   mylisti+=[i+1.5,i+1.5]
                   mylistj+=[j+.5,j+1.5]
                   ax.plot([i+1.5,i+1.5], [j+.5,j+1.5], linewidth=3,linestyle='-',color='#000000') #rechte blockline         
        #zorgt voor golflijn met stappen van 10 horizontaal
        for i in range(fileObject.numberOfColumnsInArray):
            for j in range(fileObject.numberOfRowsInArray-1):
                if (array[j, i]<=iIsochrone and array[j+1, i]>iIsochrone) or (array[j, i]>iIsochrone and array[j+1, i]<=iIsochrone):
                    ax.plot([i+.5,i+1.5], [j+1.5,j+1.5], linewidth=3,linestyle='-',color='#000000') #rechte blockline```
Sheldon
  • 4,084
  • 3
  • 20
  • 41
  • i tried to use that post but i get the error that my list indez is out of range. i used n=0 to be sure that he picked a line but even with n=0 i got this error – Sorsha Mar 03 '21 at 11:25
  • I suggest another solution in my edited answer. Hope this helps! – Sheldon Mar 03 '21 at 12:08