用多个x轴标记y轴'

时间:2016-10-14 01:04:44

标签: python multiple-axes

我在不同的比例上设置了一个带有3个x轴的图表,但是当我尝试使用Y标签时,我得到错误:

AttributeError:'function'对象没有属性'ylabel'

我尝试了很多选项,但我不确定为什么会出现此错误。

我的代码:

fig, ax = plt.subplots()

fig.subplots_adjust(bottom=0.30)

ax1 = ax.twiny()
ax2 = ax.twiny()

ax1.set_frame_on(True)
ax1.patch.set_visible(False)
ax1.xaxis.set_ticks_position('bottom')
ax1.xaxis.set_label_position('bottom')
ax1.spines['bottom'].set_position(('outward', 60))

ax.plot(temp1, depth1, "r-")
ax1.plot(v1, depth1, "g-.")
ax2.plot(qc1, depth1, "b--")

ax1.axis((0, 200, 0, 20))
ax.invert_yaxis()
ax.xaxis.set_major_locator(MaxNLocator(integer=True))

ax.set_xlabel('Temperature [\N{DEGREE SIGN}C]', color='r')
ax1.set_xlabel('Volumetric moisture content [%]', color='g')
ax2.set_xlabel('Cone tip resistance [MPa]', color='b')

ax.set.ylabel('Depth [m]')

for tl in ax.get_xticklabels():
    tl.set_color('r')
for tl in ax1.get_xticklabels():
    tl.set_color('g')
for tl in ax2.get_xticklabels():
    tl.set_color('b')

ax.tick_params(axis='x', colors='r')
ax1.tick_params(axis='x', colors='g')
ax2.tick_params(axis='x', colors='b'

1 个答案:

答案 0 :(得分:0)

你正在输入ax.set.ylabel,你应该做ax.set_ylabel

相关问题