# Surface plot with pyplot - order of axes

**URL:** <https://discourse.julialang.org/t/surface-plot-with-pyplot-order-of-axes/9282>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [February 23, 2018, 5:13pm UTC](https://discourse.julialang.org/t/surface-plot-with-pyplot-order-of-axes/9282 "2018-02-23T17:13:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hurak](https://avatars.discourse-cdn.com/v4/letter/h/5daacb/32.png) [@hurak](https://discourse.julialang.org/u/hurak)\
**Post date:** [February 23, 2018, 5:13pm UTC](https://discourse.julialang.org/t/surface-plot-with-pyplot-order-of-axes/9282/1 "2018-02-23T17:13:58Z")

</div>

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?

 ![surfaceplot](https://global.discourse-cdn.com/julialang/original/3X/e/3/e317bf97c700444293a08a45afd3896a4d3fe3fd.png)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [February 23, 2018, 5:18pm UTC](https://discourse.julialang.org/t/surface-plot-with-pyplot-order-of-axes/9282/2 "2018-02-23T17:18:30Z")

</div>

> [@hurak](#):
>
> 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?

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

---

<div class="post-metadata">

**Author:** ![hurak](https://avatars.discourse-cdn.com/v4/letter/h/5daacb/32.png) [@hurak](https://discourse.julialang.org/u/hurak)\
**Post date:** [February 23, 2018, 7:31pm UTC](https://discourse.julialang.org/t/surface-plot-with-pyplot-order-of-axes/9282/3 "2018-02-23T19:31:47Z")

</div>

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 🙂 Thank you.
