
#ax.scatter3D(cParams, gammas, avg_errors_array, zdir='z',cmap='viridis')ĭf = pd.DataFrame() #ax.plot3D(cParams, gammas, avg_errors_array)


#ax.plot_wireframe(cParams, gammas, avg_errors_array)
PLOT SURFACE VECTOR 2D CODE
The code looks like this: fig = plt.figure() ax.plot3D(cParams, gammas, avg_errors_array) - similar to wireframe.plot_wireframe(cParams, gammas, avg_errors_array) - this works, but will look ugly if your data isn't sorted nicely, as is potentially the case with massive chunks of real scientific data.scatter3D(cParams, gammas, avg_errors_array) - this works but is overly simplistic.There are many potential choices to plot the data: In my case these were c,gamma, and errors because I was testing a support vector machine. To elaborate, suppose your x,y,z are some arbitrary variables. If you have 3d scattered data in 3 separate arrays, pandas is an incredible help and works much better than the other options. Just to chime in, Emanuel had the answer that I (and probably many others) are looking for. # ~~~~ MODIFICATION TO EXAMPLE ENDS HERE ~~~~ # Plt.title('Meshgrid Created from 3 1D Arrays') Surf = ax.plot_surface(x2, y2, z2, rstride=1, cstride=1, cmap=cm.coolwarm, # put the data into a pandas DataFrame (this is what my data looks like)ĭf = pd.DataFrame(xyz, index=range(len(xyz))) # ~~~~ MODIFICATION TO EXAMPLE BEGINS HERE ~~~~ # Adding this next bit on creates the same plot from 3 1-D arrays. Surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,Īx.t_major_locator(LinearLocator(10))Īx.t_major_formatter(FormatStrFormatter('%.02f')) from mpl_toolkits.mplot3d import Axes3Dįrom matplotlib.ticker import LinearLocator, FormatStrFormatter My data happened to be in a pandas.DataFrame so here is the ot_surface example with the modifications to plot 3 1-D arrays. I have evenly spaced data that is in 3 1-D arrays instead of the 2-D arrays that matplotlib's plot_surface wants. Interactive_plot = interactive(plot, i=(2, 10)) Theta = 2 * np.pi * np.random.random(1000)Īx.plot_trisurf(x, y, z, cmap='viridis', edgecolor='none')
PLOT SURFACE VECTOR 2D HOW TO
I was wondering how to do some interactive plots, in this case with artificial data from _future_ import print_functionįrom ipywidgets import interact, interactive, fixed, interact_manual surf = ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.1, vmin=0, vmax=2000) If necessary you can pass vmin and vmax to define the colorbar range, e.g. Surf = ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.1) X,y,z = np.loadtxt('your_file', unpack=True) Please note, if your surface includes complex numbers, only the real part will be plotted.You can read data direct from some file and plot from mpl_toolkits.mplot3d import Axes3D The resolution slider can be used to increase the number of data points displayed on the graph, which gives a smoother final result, but since this needs more computational power, you may notice a slight decrease in frame rate when interacting with the graph.Įvery time you hit the "Calculate" button, the URL updates with your current settings meaning you can share a link directly to a graph of your choice without having to keep typing in the settings. You can also enter a third option which will be plotted if the first condition is not met - for example "if (x > y, x*x - y*y, x)" will plot \(x^2\) - \(y^2\) in all areas where \( x \) is greater than \( y\), and \(x \) in all areas where x is not greater than y. If, for example, you wanted to show the funtion \(x^2\) - \(y^2\) but only in areas where \(x\) is greater than \(y\), you would enter "if (x > y, x*x - y*y)" in the expression box. You can also apply certain constraints/inequalities to the graph. The square root of x (for positive x only) The inverse of the three trigonometric functions listed above The table below lists which functions can be entered in the expression box. Clicking on the graph will reveal the x, y and z values at that particular point.

The graph can be zoomed in by scrolling with your mouse, and rotated by dragging around. When you hit the calculate button, the demo willĬalculate the value of the expression over the x and y ranges provided and then plot the result as a surface. This demo allows you to enter a mathematical expression in terms of x and y.
