-2

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......

usethedeathstar
  • 2,219
  • 1
  • 19
  • 30
Abdallah
  • 71
  • 1
  • 7

1 Answers1

1
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())
usethedeathstar
  • 2,219
  • 1
  • 19
  • 30
  • Sorry but i don't understand what you mean by numpy.flatten and why are you introducing new variables x,y,z – Abdallah Jan 24 '14 at 15:55
  • @Abdallah What are your X,Y,x ? They are numpy.ndarrays i guess? and new variables are used here since i use this piece of code as well for stuff in which my x,y are not from something like a square where you have a datapoint everywhere, so it is more general in its use. Edit: i updated my solution so you can just copypaste it to try and see if you like this way of visualization. – usethedeathstar Jan 24 '14 at 15:59
  • gammas is include in [0,pi/2] same for psis, I substitute x with gammas, y with psis, z with x, after executing this programm i see no plot is it normal ? – Abdallah Jan 24 '14 at 16:04
  • @Abdallah i updated my post a little, try again with the updated version? – usethedeathstar Jan 24 '14 at 16:06
  • After executing i have this error : 'module' object has no attribute 'flatten' – Abdallah Jan 24 '14 at 16:09
  • @Abdallah i updated it, with the correct Y.flatten() instead of numpy.flatten(Y) - does it work now? Note: i know i should move this to chat, but Abdallah does not have enough rep on this site to be able to talk in chat – usethedeathstar Jan 24 '14 at 16:19