在matplotlib上使用对数刻度时设置刻度之间的间隔

时间:2017-08-22 05:30:01

标签: python matplotlib plot

这是我使用Google表格在3D中执行的图表。

enter image description here

我想在matplotlib上实现相同的比例但是使用3D表面。 问题是,logscale上的刻度被放置在“应该是”的位置,如果它是正常的刻度。 enter image description here

这是我的代码:

X, Y = np.meshgrid(numrec, numtreino)

Z = (numerador/(((rec[0])+(treino[0]*60))/((rec[1])+(treino[1]*60))))*X

# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
                       linewidth=2, antialiased=True, alpha=0.8)

ax.set_xscale('symlog')
ax.set_yscale('symlog')
ax.invert_xaxis()


# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)

plt.show()

1 个答案:

答案 0 :(得分:0)

正如ImportanceOfBeingErnest所指出的,它似乎是matplotlib中的一个错误。

如果在执行3D散点图时启用对数刻度,则不会创建任何内容并且程序崩溃。 ax.set_xscale('log')而不是ax.set_xscale('symlog')

为了解决缩放问题我已经改变了:

Z = (numerador/(((rec[0])+(treino[0]*60))/((rec[1])+(treino[1]*60))))*X

# Plot the surface.

为:

Z = (numerador/(((rec[0])+(treino[0]*60))/((rec[1])+(treino[1]*60))))*X

X = np.log10(X)
Y = np.log10(Y)
# Plot the surface.

设置我添加的标记:

zticks = [ 1e3, 1e2, 1e1]
ax.set_xticks(np.log10(zticks))
ax.set_xticklabels(zticks)

enter image description here

相关问题