matplotlib Axes.secondary_xaxis引发错误

时间:2020-11-09 08:32:21

标签: python matplotlib valueerror

我一直在尝试向绘图添加一个附加轴,但是我一直收到错误消息:“要解压缩的值太多(预期2)”。我像the documentation says那样做-传递函数的元组。这是代码:

def forward(ignored):
    return climate_change.index


def inverse(ignored):
    return np.flip(climate_change.index)


fig, ax = plt.subplots()
ax.scatter(climate_change['co2'], climate_change['relative_temp'], c=climate_change.index)
ax.set_xlabel('CO2 [ppm]')
ax.set_ylabel('Relative temperature [°C]')
# Throws "too many values to unpack (expected 2)"
secax = ax.secondary_xaxis('top', functions=(forward, inverse))
secax.set_xlabel('Time [year]')
plt.show()

0 个答案:

没有答案