I am trying to plot the solutions of a minimization problem,

'X, Y = meshgrid(gammas, psis)'

gammas and psis are my 2 axes,

'mplot3d(X, Y, x)'

x is the solution of my problem, While executing my script : name 'mplot3d' is not defined......

有帮助吗?

解决方案

import pylab
def scatterme(x, y, z):
    pylab.figure()
    imi = pylab.scatter(x, y, c = z, edgecolor = "none")
    pylab.colorbar(imi)
    pylab.show()

In this case, my x and y are what for you would be X.flatten() and Y.flatten() and the z would be your x.flatten(). This code also works if your data does not come from something square, so if you just want to see what something looks like, if you have a lot of x and y values, and for each one you have a z, this shows you what you want as well.

Note: this is not a 3D plot, but i (personnal opinion) feel that a scatterplot in which the z-dimension is your colorbar seems to show much more what you need to know, compared to a 3D plot that you have to rotate around all the time, to be able to see at the angle that might show you something you want to know

Edit: for the full code, that you can just copypaste (put this after the first piece in my post)

import numpy
X,Y = meshgrid(gammas, psis)
scatterme(X.flatten(), Y.flatten(), x.flatten())
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top