将3D绘图的轴放在图形内

问题描述 投票:2回答:1

如何将3D绘图的轴放置在图形本身内而不是图形边缘上?

我需要这个:

drawing_with_axes_inside


而不是默认情况下在绘图框边缘的当前轴:

current_graph_with_axes_on_edges

码:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


fig = plt.figure()
ax = fig.add_subplot(2, 1, 1, projection='3d')
x = np.linspace(-1, 1, 300)


# equivalent to f=R(x)*e^ix
f = np.e**(15*1j*x - 18 * x**4)
real_f = np.real(f)
im_f = np.imag(f)
f_conj = np.conjugate(f)
im_f_conj = np.imag(f_conj)

# 1st plot
ax.scatter(x, real_f, im_f, label='Ψ ', color='b')
plt.title("The complex conjugate of Ψ\nis its mirror image.")

ax.legend()
ax.set_xlabel("x")
ax.set_ylabel("Re")
ax.set_zlabel("Im")
# ax.set_axis_off() removes the box as well
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])

# 2nd plot
ax = fig.add_subplot(2, 1, 2, projection='3d')
ax.scatter(x, real_f, im_f_conj, label='Ψ *', color='r')

ax.legend()
ax.set_xlabel("x")
ax.set_ylabel("Re")
ax.set_zlabel("Im")
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])

plt.show()
python matplotlib plot 3d complex-numbers
1个回答
3
投票

目前看来,没有支持3D绘图的实现(@ThomasKühn指出了规范方法和问题。一种天真的方法和uggly方法只是将线条绘制为轴,但是这里没有任何刻度他们。

编辑:可以为轴限制添加文本

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


fig = plt.figure(figsize = (20,20))
ax = fig.add_subplot(2, 1, 1, projection='3d')
x = np.linspace(-1, 1, 300)


# equivalent to f=R(x)*e^ix
f = np.e**(15*1j*x - 18 * x**4)
real_f = np.real(f)
im_f = np.imag(f)

# 1st plot
ax.scatter(x, real_f, im_f, label='Ψ ', color='b')
plt.title("The complex conjugate of Ψ\nis its mirror image.")

ax.legend()
ax.set_xlabel("x")
ax.set_ylabel("Re")
ax.set_zlabel("Im")
# ax.set_axis_off() removes the box as well
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])


ax.plot([x.min(), x.max()], [0,0], [0,0], color = 'black')
ax.plot([0, 0], [real_f.min(), real_f.max()], [0, 0], color = 'black')
ax.plot([0, 0], [0,0], [im_f.min(), im_f.max()], color = 'black')

ax.text(0,0,0, '0')
ax.text(x.max(),0,0, x.max())
ax.text(x.min(), 0, 0, x.min())

ax.text(0, real_f.max(), 0, real_f.max().round(2))
ax.text(0, real_f.min(), 0, real_f.min().round(2))

ax.text(0, 0, im_f.max(), imf_f.max().round(2))
ax.text(0, 0, imf_min(), im_f.min().round(2))
ax.axis('off')
plt.show()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.