简体   繁体   中英

No exponential form of the z-axis in matplotlib-3D-plots

I have a similar problem as described in How to prevent numbers being changed to exponential form in Python matplotlib figure :

I don't want that (in my special case) weird scientific formatting of the axis. My problem is different as I have this problem at my z -Axis. For 2-D plots I can use ax.get_yaxis().get_major_formatter().set_useOffset(False) . And there is no function ax.get_zaxis()

What do I use to format my z -Axis the same way?

EDIT: Example:

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()

在此处输入图片说明

As you say, there is no get_zaxis() method. But, fortunately, there is zaxis field (so don't add () ). There are also xaxis and yaxis fields, so you can use all of those uniformly instead of get_...axis() if you like.

For example:

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

and the end result should look something like this:

不使用指数形式的新图

As you can see, for large numbers it might not look so well...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM