Surface plot with pyplot - order of axes

plotting

#1

Hi,

I seem to be having troubles to understand the very basic usage of functions for 3D graphs such as surface (and Plots and PyPlot). See the screenshot.

In particular, I am quite confused by the fact that surface plots comes with the x1 and x2 axes (or x and y, if you like) exchanged. I can solve my problem for the time being, just be transposing the z_data array, but I am still not quite happy about it because I do not understand the reason for such behavior of the software. The code seems to be pretty clear. Nevertheless, I suspect the culprit is on line 3 where I am using list comprehension to build the 2D array of function values. Any explanation and recommendation of the right “Julian” way to write such code for a beginner?


#2

It may be because Python is row major and so matplotlib has some convention to read row -> column instead of column -> row?


#3

Indeed, it was just enough to flip the arguments in the list comprehension on line 3, that is, the new line 3 is

z_data = [f([x1,x2]) for x2=x2_data, x1=x1_data];

and things are fine.

Apparently, I did not fully understand how the list comprehension works (I am not yet fluent with Python either). I did not realize that the order determines which loop is the outer and which loop is inside.

Thanks to this plotting issue I made another step in understanding the basics of the language :slight_smile: Thank you.