python数据可视化7

5 对数坐标轴及其他非线性坐标轴

matplotlib.pyplot不仅支持线性坐标轴,而且还支持对数和逻辑坐标轴(在数据跨越多个数量级时使用)。

plt.xscale('log')
np.random.seed(19680801)

mu = 0.5
sigma = 0.4
y = np.random.normal(mu, sigma, size=1000)
y = y[(y > 0) & (y < 1)]
y.sort()
x = np.arange(len(y))

# 绘图
plt.figure(1
        )

# linear
plt.subplot(221)
plt.plot(x, y)
plt.yscale('linear')
plt.title('linear')
plt.grid(True)


# log
plt.subplot(222)
plt.plot(x, y)
plt.yscale('log')
plt.title('log')
plt.grid(True)


# symmetric log
plt.subplot(223)
plt.plot(x, y - y.mean())
plt.yscale('symlog', linthreshy=0.01)
plt.title('symlog')
plt.grid(True)

# logit
plt.subplot(224)
plt.plot(x, y)
plt.yscale('logit')
plt.title('logit')
plt.grid(True)

plt.gca().yaxis.set_minor_formatter(NullFormatter())
plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25, wspace=0.35)

6. 设置全局渲染方式

可以调用style.available看看有哪些渲染方式,在绘图之初调用style.use()函数,指定渲染方式后,就可以对所有后续作图都使用相同方式进行渲染。

print (plt.style.available)
plt.style.use(u"ggplot")
原文地址:https://www.cnblogs.com/xrj-/p/14455151.html