如何在z轴中更改字体参数?

发布于 2025-02-06 10:15:01 字数 1345 浏览 0 评论 0 原文

我正在尝试个性化我的一些图形,因此我想更改所有轴的字体。我为此写了代码。问题是我无法更改Z轴的字体。有人有建议吗?

提前致谢。

import matplotlib.pyplot as plt
from matplotlib import cm

font = {'size'   : 12}

cm=1/2.54

size_x = 10*cm
size_y = 8*cm
min_limx = 4
max_limx = 10
min_limy = 0
max_limy = 50
min_limz = 0
max_limz = 8
#%%
fig, ax = plt.subplots(figsize=(size_x, size_y), subplot_kw={"projection": "3d"})
X, Y = np.meshgrid(xnew, ynew, indexing='ij')
Z1 = m_fill
Z2 = m_nofill
surf = ax.plot_surface(X, Y, Z1, cmap=cm.viridis, linewidth=0, antialiased=False)
surf = ax.plot_surface(X, Y, Z2, color='w', linewidth=0, antialiased=False)

ax.set_xlabel('$\lambda$', **font)
ax.set_ylabel('$\chi$', **font)
ax.set_zlabel('$\it{m_{0}, кг}$', **font)

lin_x = np.arange(min_limx, max_limx, step=2)
lin_y = np.arange(min_limy, max_limy, step=15)

plt.xticks(lin_x, **font)
plt.yticks(lin_y, **font)
#plt.zticks(lin_z, **font) # AttributeError: module 'matplotlib.pyplot' has no attribute 'zticks'
ax.set_zlim(0, 8, )


#plt.gca().set_aspect('equal', adjustable='box')
ax.view_init(45, -45)
#plt.tight_layout()
plt.grid()
plt.show()
fig.savefig('p0_V_m0.png', format='png', dpi=300)

PS:这就是现在的外观。

I'm trying to personalize some of my graphs so I'd like to change the font of all axis. I wrote the code below for that. The problem is that I can't change the font of the z axis. Somebody have a recommendation?

Thanks in advance.

import matplotlib.pyplot as plt
from matplotlib import cm

font = {'size'   : 12}

cm=1/2.54

size_x = 10*cm
size_y = 8*cm
min_limx = 4
max_limx = 10
min_limy = 0
max_limy = 50
min_limz = 0
max_limz = 8
#%%
fig, ax = plt.subplots(figsize=(size_x, size_y), subplot_kw={"projection": "3d"})
X, Y = np.meshgrid(xnew, ynew, indexing='ij')
Z1 = m_fill
Z2 = m_nofill
surf = ax.plot_surface(X, Y, Z1, cmap=cm.viridis, linewidth=0, antialiased=False)
surf = ax.plot_surface(X, Y, Z2, color='w', linewidth=0, antialiased=False)

ax.set_xlabel('$\lambda

Ps: This is how the figure looks like right now.

enter image description here

, **font) ax.set_ylabel('$\chi

Ps: This is how the figure looks like right now.

enter image description here

, **font) ax.set_zlabel('$\it{m_{0}, кг}

Ps: This is how the figure looks like right now.

enter image description here

, **font) lin_x = np.arange(min_limx, max_limx, step=2) lin_y = np.arange(min_limy, max_limy, step=15) plt.xticks(lin_x, **font) plt.yticks(lin_y, **font) #plt.zticks(lin_z, **font) # AttributeError: module 'matplotlib.pyplot' has no attribute 'zticks' ax.set_zlim(0, 8, ) #plt.gca().set_aspect('equal', adjustable='box') ax.view_init(45, -45) #plt.tight_layout() plt.grid() plt.show() fig.savefig('p0_V_m0.png', format='png', dpi=300)

Ps: This is how the figure looks like right now.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

り繁华旳梦境 2025-02-13 10:15:01

The fontsize of the tick labels is set labelsize 参数:

import matplotlib.pyplot as plt

fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

font = {'size': 20}
ax.tick_params('z', labelsize=font['size'])

(为所有三个轴设置标签大小,您可以使用 ax。 tick_params(labelsize = 20)。)

The fontsize of the tick labels is set by the labelsize parameter:

import matplotlib.pyplot as plt

fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

font = {'size': 20}
ax.tick_params('z', labelsize=font['size'])

enter image description here

(To set the label size for all three axes you can use ax.tick_params(labelsize=20).)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文