[Matplotlib-users] Add and remove points to a scatter plot repeatedly

regev81 regev81 at gmail.com
Tue Dec 3 10:09:31 EST 2019


I am trying to add and remove points to a scatter plot repeatedly, each time
with a different set of points,  while a wireframe plot is in the
background.
is there a way to do so with out closing the all figure window and the
background wireframe plot?

Thanks

Here is my python code:
import gdal
from mpl_toolkits.mplot3d.axes3d import *
import matplotlib.pyplot as plt
from pathlib import Path

#import the raster tif file and convert to 2d array
dataset = gdal.Open("dem_demo.tif")
dem_arr = dataset.ReadAsArray()

#slicing
#dem_arr[start row:end row,start col:end col]
sliced_dem_arr = dem_arr[100:151,100:151]
rowCount = sliced_dem_arr.shape[0]
colCount = sliced_dem_arr.shape[1]

#set the X, Y, Z arrays for plotting process
rowArr = np.arange(1,rowCount+1)
colArr = np.arange(1,colCount+1)
X, Y = np.meshgrid(rowArr, colArr)
Z = sliced_dem_arr

#set 3d view ans labels
ax = plt.axes(projection='3d')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')

############plotting the dtm ########################
###wireframe
ax.plot_wireframe(X, Y, Z, color='green')

#Add points #01
points_list = [(2,6),(30,14),(39,15)]
for p in points_list:
    ax.scatter(p[0], p[1], sliced_dem_arr[p[0],p[1]], c = 'r')
plt.show()

#Add points #02
points_list2 = [(5,23),(24,4),(12,45)]
for p in points_list2:
    ax.scatter(p[0], p[1], sliced_dem_arr[p[0],p[1]], c = 'r')
plt.show()

<http://matplotlib.1069221.n5.nabble.com/file/t5275/example.jpeg> 



--
Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html


More information about the Matplotlib-users mailing list