About Python matplotlib 3-D Graph Display

Asked 2 years ago, Updated 2 years ago, 49 views

I have recently started matplotlib, and thank you for your help on this site.
I have seen many questions and answers, but there were no questions about what I wanted to do, so I would like to ask you for the first time.

I am writing a three-dimensional graph on the Axes 3D of matplotlib.
The x-axis y-axis of the graph is set to be 0 to 20, and the z-axis is set to be 0 to 10, but all axes are of the same size (cubic) when displayed.

In that case, how do I display a graph where the z-axis is half the size (rectangular parallelepiped) of the other two axes?
I've also looked at websites such as English, but I'm not good at English...

I am very sorry for the rudimentary question, thank you for your cooperation.

Dear Tatz Sekine, Thank you for your comment.I'm sorry that it's my first time posting and I don't understand how to use it.
Can't you reply to the comments?
I saw the link.Does that mean I have to give up on 3D…
Thank you for your prompt reply

Dear Harry0000, Dear mjy, Thank you for your comment.Apparently, I have created two accounts, M. sentan and user17177...Sorry for the inconvenience.Thank you for attaching the link.I would like to use it as a reference and unify it.
Dear metropolis, Thank you for your reply!!It's very instructive.

M. sentan and user17177 are the same person, sorry for confusing you.

python matplotlib

2022-09-30 18:08

1 Answers

The environment here is as follows, but

  • Python 2.7.12
  • matplotlib (Axes 3D) 1.5.1

set_aspect(0.5) gives a plot diagram that looks like the X-Z or Y-Z aspect ratio is 0.5.

plot_3d.py

 from mpl_tools.mplot3d import Axes 3D
import matplotlib.pyplot asplt
import numpy as np

config=plt.figure()
ax=fig.gca(projection='3d')
ax.set_aspect(0.5)

x = np.random.rand(100)*20
y=np.random.rand(100)*20
z=np.random.rand(100)*10

ax.set_xlim(0,20)
ax.set_ylim(0,20)
ax.set_zlim(0,10)

ax.scatter(x,y,z)

plt.grid()
plt.show()



Display Results

figure


2022-09-30 18:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.