gpt4 book ai didi

python - 调整 matplotlib 中 3D 图的轴标签和名称方向

转载 作者:太空狗 更新时间:2023-10-29 18:08:35 26 4
gpt4 key购买 nike

enter image description here

我正在使用 matplotlib 制作这个 3D 图:

ax.plot_surface(x_surf, y_surf, np.reshape(npp, (max_temp/step, max_temp/step)), linewidth=0.2,cmap=palettable.colorbrewer.sequential.Greens_9.mpl_colormap)

如何使轴标签和轴名称看起来更像这个图: enter image description here

最佳答案

据我了解,您想更改“轴标签”和“轴名称”。

不幸的是,我只能做其中的一部分(我希望这对您来说是的东西,并且其他人可以找到它的第二部分):

enter image description here

enter image description here

我在 http://matplotlib.org/examples/mplot3d/pathpatch3d_demo.html 中做了一些修改为了得到上面的图像

import matplotlib.pyplot as plt
from matplotlib.patches import Circle, PathPatch
# register Axes3D class with matplotlib by importing Axes3D
from mpl_toolkits.mplot3d import Axes3D
import mpl_toolkits.mplot3d.art3d as art3d
from matplotlib.text import TextPath
from matplotlib.transforms import Affine2D

def text3d(ax, xyz, s, zdir="z", size=None, angle=0, usetex=False, **kwargs):

x, y, z = xyz
if zdir == "y":
xy1, z1 = (x, z), y
elif zdir == "y":
xy1, z1 = (y, z), x
else:
xy1, z1 = (x, y), z

text_path = TextPath((0, 0), s, size=size, usetex=usetex)
trans = Affine2D().rotate(angle).translate(xy1[0], xy1[1])

p1 = PathPatch(trans.transform_path(text_path), **kwargs)
ax.add_patch(p1)
art3d.pathpatch_2d_to_3d(p1, z=z1, zdir=zdir)


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ax.tick_params(axis='x',direction='out', length=6, width=2, colors='r')

text3d(ax, (4, -2, 0), "X-axis", zdir="z", size=.5, usetex=False,
ec="none", fc="k")
text3d(ax, (12, 4, 0), "Y-axis", zdir="z", size=.5, usetex=False,
angle=.5*3.14159, ec="none", fc="k")
text3d(ax, (12, 10, 4), "Z-axis", zdir="y", size=.5, usetex=False,
angle=.5*3.14159, ec="none", fc="k")

ax.set_xlim3d(0, 10)
ax.set_ylim3d(0, 10)
ax.set_zlim3d(0, 10)

plt.show()

我期待在 http://matplotlib.org/api/axes_api.html 找到如何开发这个问题的第二部分, 但我还没有找到。

希望对你有帮助

关于python - 调整 matplotlib 中 3D 图的轴标签和名称方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37324837/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com