缺少轴标签

时间:2018-11-21 14:07:40

标签: python-3.x matplotlib

我正在尝试创建3D图,但是z轴标签存在问题。它根本不会出现在图中。我该如何修改?代码如下

# Gamma vs Current step 2
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

h = np.arange(0.1,5.1,0.1)
gamma = np.arange(0.1,5.1,0.1)
sigmaz_hgam = np.array([.009998,.03988,.08878,.15403
,.230769,.312854,.394358,.4708311,.539697879,.6,.6518698
,.696033486,.73345752165,.7651390123,.792,.814845635
,.8343567,.851098499,.865535727,.8780487,.8889486,.89848986
,.906881,.914295,.9208731,.9267338,.93197569,.93668129
,.9409202379,.94475138,.951383,.9542629,.956895,.959309
,.961526,.9635675,.96545144,.9671934,.968807,.97030539
,.9716983,.972995,.974206,.975337,.97639567,.977387,.978318
,.97919266,.98,.9807902])

mu = 1
sigmaz_hgam = mu*sigmaz_hgam
# creates an empty list for current values to be stored in
J1 = []

for i in range(sigmaz_hgam.size):
    expec_sz = sigmaz_hgam[i]
    J = 4*gamma[i]*(mu-expec_sz)
    J1.append(J.real)
    #print(J)

这部分代码是用来找出问题所在的地方

mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')

x = h
y = gamma
z = J1

ax.plot(x, y, z, label='Dephasing Model')
ax.legend()

ax.set_xlabel('h', fontsize=10)
ax.set_ylabel('$\gamma$')
ax.yaxis._axinfo['label']['space_factor'] = 3.0
for t in ax.zaxis.get_major_ticks(): t.label.set_fontsize(10)
# disable auto rotation
ax.zaxis.set_rotate_label(False) 
ax.set_zlabel('J', fontsize=10, rotation = 0)


plt.show()

enter image description here

1 个答案:

答案 0 :(得分:1)

在我的Matplotlib(2.0.2)版本上,在Mac上,我看到了标签(在那里-大多数只是从您的情况下裁剪出图像)。 您可以尝试减少刻度和标签之间的填充:

ax.zaxis.labelpad = 0