python matplotlib画图设置坐标刻度为10^n

阅读本文前需知道:matplotlib.pyplot函数

普通坐标刻度

import matplotlib.pyplot as plt
y=[pow(10,i) for i in range(0,10)]
x=range(0,len(y))
plt.plot(x, y, 'r')
plt.show()

python matplotlib画图设置坐标刻度为10^n_第1张图片

纵坐标刻度为10^n

import matplotlib.pyplot as plt
y=[pow(10,i) for i in range(0,10)]
x=range(0,len(y))
plt.plot(x, y, 'r')
plt.yscale('log')#设置纵坐标的缩放
plt.show()

python matplotlib画图设置坐标刻度为10^n_第2张图片

pyplot.yscale() 就是设置纵坐标轴缩放的函数,不设置默认为 pyplot.yscale(‘linear’) 线性刻度
注: plt.yscale(‘log’) 无法显示负值,如

import matplotlib.pyplot as plt
y=[-pow(10,i) for i in range(0,10)]#y=-10^i
x=range(0,len(y))
plt.plot(x, y, 'r')
plt.yscale('log')
plt.show()

python matplotlib画图设置坐标刻度为10^n_第3张图片

可用 plt.yscale(‘symlog’) 正负都可显示

import matplotlib.pyplot as plt
y=[-pow(10,i) for i in range(0,10)]#y=-10^i
x=range(0,len(y))
plt.plot(x, y, 'r')
plt.yscale('symlog')
plt.show()

python matplotlib画图设置坐标刻度为10^n_第4张图片

同样 pyplot.xscale() 是设置横坐标缩放的函数

import matplotlib.pyplot as plt
y=[pow(10,i) for i in range(0,10)]
x=range(0,len(y))
plt.plot(x, y, 'r')
plt.xscale('symlog')
plt.show()

python matplotlib画图设置坐标刻度为10^n_第5张图片

你可能感兴趣的:(技术使用)