4

I know that matplotlib is not the best choice for 3D visualization but I have tried in vane to get other packages such as Mayavi to work (my version of openGL prevents it). My issue is that when I create a 3D plot and I rotate it, the plot can become distorted depending on the history of how I have rotated the plot. When I rotate to the top view of the plot from the initial position, I get what I expect. However, when I rotate to the top view from the side view (you can change ax.view_init(45,-90,)to ax.view_init(45,0,) to start from the 'side view'), the image is distorted significantly.

Here are the four views that I described. Figure one is the 'front view'. Figure 2 is the 'top view' after rotating from the 'front view'. Figure 3 is the 'side view'. Figure 4 is the 'top view' after rotating from the 'side view'.

The code I used to create the plot (although not the actual surface) is below. I am using matplotlib 2.0.0. I hope that is all that will be needed. I anticipate that this might not be fixable but I would appreciate any input.

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.view_init(45,-90,)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.xlim(0,pL)
plt.ylim(0,pW)
ax.set_aspect("equal")
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
ax.grid(False)

plt.show()

So that my plot can be duplicated:

ax.plot_trisurf(x,y,z, linewidth=0.2, antialiased=True)
x=[-2.8284271247461898,0,2.8284271247461907,5.6568542494923806,-2.8284271247461898,0,8.4852813742385713,11.313708498984761,3.3137084989847598,6.1421356237309492,14.142135623730953,16.970562748477143,8.9705627484771409,11.798989873223331,19.798989873223331,22.627416997969522,14.627416997969521,17.45584412271571,25.45584412271571,28.284271247461902,20.284271247461902,23.112698372208094,24,26.828427124746192]
y=[2.8284271247461894,5.6568542494923797,-2.8284271247461903,0,8.4852813742385695,11.313708498984759,-2.8284271247461898,0,8,10.82842712474619,-2.8284271247461898,0,8,10.82842712474619,-2.8284271247461898,0,8,10.82842712474619,-2.8284271247461898,0,8,10.82842712474619,4.284271247461902,7.1126983722080919]
z=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
iacob
  • 20,084
  • 6
  • 92
  • 119
Alex Santelle
  • 935
  • 2
  • 8
  • 9

1 Answers1

0

As of v3.3 matplotlib's Axes3d no longer distorts the 3D plot to match the 2D aspect ratio:

Plots made with Axes3D were previously stretched to fit a square bounding box. As this stretching was done after the projection from 3D to 2D, it resulted in distorted images if non-square bounding boxes were used. As of 3.3, this no longer occurs.

iacob
  • 20,084
  • 6
  • 92
  • 119