Can't set axis scale to logarithmic in 3D plot in matplotlib

喜你入骨 提交于 2021-01-27 20:01:13

问题


I would like to 3D plot the surface of a data 2d array with dimension [50,250]. Two of the axes (x, z) should be in logarithmic scale. Here's a MWE:

import numpy as np
xx = np.asanyarray([np.ones([250])*(m+1) for m in range(50)])
yy = np.asanyarray([range(250) for m in range(50)])
zz = np.asanyarray([np.sqrt(np.arange(250)*m) for m in range(50)])

import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(xx, yy, zz, cmap=cm.coolwarm,
                       linewidth=0, antialiased=False)

ax.yaxis.set_scale('log')

All other answers I found indicate that this last line should do the trick. Instead, it raises the following AttributeError: 'YAxis' object has no attribute 'set_scale'

I don't get why it does so. I have the latest version of matplotlib installed in my Mac Osx 10.9.7 (that is 2.1.0).

Can anybody assist me on this one?

来源:https://stackoverflow.com/questions/46891692/cant-set-axis-scale-to-logarithmic-in-3d-plot-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!