3D scatter plot with 'unlimited' Z axis

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

3D scatter plot with 'unlimited' Z axis

Will Furnell
Hey everyone,

I'm looking into a 3D scatter plot - basically converting a NumPy array
to a 3D plot, where X and Y correspond to the X and Y co-ordinates on
the graph and the Z values corresponds to a particular height on the graph.

This is how I'm generating the lists:


x = list(range(0, 256))
y = list(range(0, 256))
z = []

for i in range(0, 255):
    for j in range(0, 255):
        z.append(ll[i][j])

where ll is my 2D array...

I've seen the scatter function with 3d projection, but this requires the
Z array length to be the same length as the X and Y lengths, whereas
I'll need to be plotting X*Y points (256*256). Is there some way that I
could achieve this?

Thanks,

Will.
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: 3D scatter plot with 'unlimited' Z axis

Benjamin Root
```
x = np.arange(256)
y = np.arange(256)
xx, yy = np.meshgrid(x, y)
```
Then your `xx` and `yy` will be 2D, just like your `ll` variable. Then, you pass the flattened versions of those three variables (i.e., `xx.flatten()` or `xx.flat`) to the 3d scatter call.

I hope that helps!
Ben Root


On Mon, Oct 1, 2018 at 3:47 PM Will Furnell <[hidden email]> wrote:
Hey everyone,

I'm looking into a 3D scatter plot - basically converting a NumPy array
to a 3D plot, where X and Y correspond to the X and Y co-ordinates on
the graph and the Z values corresponds to a particular height on the graph.

This is how I'm generating the lists:


x = list(range(0, 256))
y = list(range(0, 256))
z = []

for i in range(0, 255):
    for j in range(0, 255):
        z.append(ll[i][j])

where ll is my 2D array...

I've seen the scatter function with 3d projection, but this requires the
Z array length to be the same length as the X and Y lengths, whereas
I'll need to be plotting X*Y points (256*256). Is there some way that I
could achieve this?

Thanks,

Will.
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: 3D scatter plot with 'unlimited' Z axis

Will Furnell
Hello Ben,

Thank you very much, this works perfectly for me!

Best,

Will.

On 01/10/2018 21:10, Benjamin Root wrote:

> ```
> x = np.arange(256)
> y = np.arange(256)
> xx, yy = np.meshgrid(x, y)
> ```
> Then your `xx` and `yy` will be 2D, just like your `ll` variable. Then,
> you pass the flattened versions of those three variables (i.e.,
> `xx.flatten()` or `xx.flat`) to the 3d scatter call.
>
> I hope that helps!
> Ben Root
>
>
> On Mon, Oct 1, 2018 at 3:47 PM Will Furnell <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hey everyone,
>
>     I'm looking into a 3D scatter plot - basically converting a NumPy array
>     to a 3D plot, where X and Y correspond to the X and Y co-ordinates on
>     the graph and the Z values corresponds to a particular height on the
>     graph.
>
>     This is how I'm generating the lists:
>
>
>     x = list(range(0, 256))
>     y = list(range(0, 256))
>     z = []
>
>     for i in range(0, 255):
>         for j in range(0, 255):
>             z.append(ll[i][j])
>
>     where ll is my 2D array...
>
>     I've seen the scatter function with 3d projection, but this requires the
>     Z array length to be the same length as the X and Y lengths, whereas
>     I'll need to be plotting X*Y points (256*256). Is there some way that I
>     could achieve this?
>
>     Thanks,
>
>     Will.
>     _______________________________________________
>     Matplotlib-users mailing list
>     [hidden email] <mailto:[hidden email]>
>     https://mail.python.org/mailman/listinfo/matplotlib-users
>
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users