【问题标题】:No exponential form of the z-axis in matplotlib-3D-plotsmatplotlib-3D-plots 中没有 z 轴的指数形式
【发布时间】:2015-06-26 11:35:40
【问题描述】:

我遇到了How to prevent numbers being changed to exponential form in Python matplotlib figure中描述的类似问题:

我不希望(在我的特殊情况下)轴的奇怪科学格式。我的问题有所不同,因为我在z-Axis 遇到了这个问题。对于二维图,我可以使用ax.get_yaxis().get_major_formatter().set_useOffset(False)。而且没有功能ax.get_zaxis()

我用什么来格式化我的z-Axis?

编辑:示例:

from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import sys
import matplotlib
import matplotlib.pyplot as pyplot

def func(xi, ti):
    res = 10e3 + np.cos(ti) * np.sin(xi)
    return res

if __name__ == '__main__':
    timeSpacing = 20
    timeStart = 0
    timeEnd = 1
    time = np.linspace(timeStart, timeEnd, timeSpacing)
    widthSpacing = 50
    widthStart = 0
    widthEnd = 3
    width = np.linspace(widthStart, widthEnd, widthSpacing)
    resList = []
    matplotlib.rcParams['legend.fontsize'] = 10
    fig = pyplot.figure()
    ax = fig.gca(projection = '3d')
    for i, item in enumerate(time):
        ti = [item for t in width]
        res = func(width, ti)
        ax.plot(width, ti, res, 'b')
    ax.set_xlabel('x')
    ax.set_ylabel('t')
    ax.set_zlabel('f(x,t)')
    pyplot.show()

【问题讨论】:

  • 显而易见的解决方法是相应地调整数据的 z 值。
  • 然后呢?然后还有一个轴比我无法正确配置。此外,一般来说,我喜欢将 f(x,y) 放在 x 和 y 上,而不是以某种让观众感到困惑的奇怪方式。
  • 你能提供一个MCVE吗?
  • 我为我的问题编辑了一个示例

标签: python matplotlib plot 3d


【解决方案1】:

正如你所说,没有get_zaxis() 方法。但是,幸运的是,有zaxis 字段(所以不要添加())。还有xaxisyaxis 字段,因此您可以统一使用所有这些字段,而不是get_...axis()

例如:

if __name__ == '__main__':
    ...
    ax = fig.gca(projection = '3d')
    ax.zaxis.get_major_formatter().set_useOffset(False) # here
    for i, item in enumerate(time):
        ...

最终结果应该是这样的:

如您所见,对于大量数字,它可能看起来不太好...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-21
    • 2011-05-02
    • 2013-02-09
    • 2021-07-22
    • 1970-01-01
    • 2014-08-11
    • 2023-04-06
    • 2014-05-26
    相关资源
    最近更新 更多