Guest User

Untitled

a guest
Dec 11th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. def scatter3d(x,y,z, cs, colorsMap='jet'):
  2. cm = plt.get_cmap(colorsMap)
  3. cNorm = matplotlib.colors.Normalize(vmin=min(cs), vmax=max(cs))
  4. scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cm)
  5. fig = plt.figure()
  6. ax = Axes3D(fig)
  7. ax.scatter(x, y, z,c=scalarMap.to_rgba(cs))
  8. ax.set_xlabel('Thita1')
  9. ax.set_ylabel('Thita2')
  10. ax.set_zlabel('Fairness (%)')
  11. scalarMap.set_array(cs)
  12. fig.colorbar(scalarMap,label='Error Rate (%)')
  13. plt.show()
  14.  
  15. def surfacePlot(x,y,z, cs, colorsMap='jet'):
  16. cm = plt.get_cmap(colorsMap)
  17. cNorm = matplotlib.colors.Normalize(vmin=min(cs), vmax=max(cs))
  18. scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cm)
  19. fig = plt.figure()
  20. ax = fig.add_subplot(111, projection='3d')
  21. ax.plot_surface(x, y, z, facecolors=scalarMap.to_rgba(cs))
  22. ax.set_xlabel('Thita1')
  23. ax.set_ylabel('Thita2')
  24. ax.set_zlabel('Fairness')
  25. scalarMap.set_array(cs)
  26. fig.colorbar(scalarMap,label='Error Rate (%)')
  27. plt.show()
  28.  
  29. grid_x, grid_y = np.meshgrid(x, y)
  30.  
  31. # I'm assuming that your data is already mesh-like, which it looks like it is.
  32. # The data would also need to be appropriately sorted for `reshape` to work.
  33. # `dx` here is number of unique x values, and `dy` is number unique y values.
  34. grid_z = z.reshape(dy, dx)
  35.  
  36. ax.plot_scatter(grid_x, grid_y, grid_z)
  37.  
  38. from scipy.interpolate import griddata
  39. xy = np.column_stack([x, y])
  40. grid_x, grid_y = np.mgrid[0:1:100j, 0:1:100j] # grid you create
  41. grid_z = griddata(xy, z, (grid_x, grid_y))
  42. ax.plot_scatter(grid_x, grid_y, grid_z)
Add Comment
Please, Sign In to add comment