Python可视化-当Matplotlib遇上matplotx

首发地址:当Matplotlib遇上matplotx

本次介绍Matplotlib的优质扩展-matplotx;

matplotx在一些方面拯救Matplotlib的不完美;

同类型文章:

Matplotlib-rcParams及绘图风格(style)设置详解

Matplotlib绘图主题(plt.style)大全

Seaborn图形外观设置


matplotx.styles.xx

matplotx整合了多种可视化主题,比Matplotlib内置主题优美,例如,

通过matplotx.styles.xx主题名称调用;

举个例子,matplotx.styles.solarized['dark']

import numpy as np
import matplotlib.pyplot as plt
import matplotx
mpl.rc_file_defaults()
plt.figure(dpi=100)

plt.style.use(matplotx.styles.solarized['dark'])
#仅需以上一行代码调用solarized的'dark'主题

plt.plot(np.arange(5.0, 10.0, 0.02),
         np.cos(2 * np.pi * np.arange(0.0, 5.0, 0.02)))
plt.title("matplotx.styles.solarized['dark']", size=15)
plt.show()

再举个例子,matplotx.styles.pitaya_smoothie['light']

import numpy as np
import matplotlib.pyplot as plt
import matplotx
mpl.rc_file_defaults()
plt.figure(dpi=100)

plt.style.use(matplotx.styles.pitaya_smoothie['light'])

plt.plot(np.arange(5.0, 10.0, 0.02),
         np.cos(2 * np.pi * np.arange(0.0, 5.0, 0.02)))
plt.title("matplotx.styles.pitaya_smoothie['light']", size=15)
plt.show()

还有很多优雅主题,如'aura', 'ayu', 'challenger_deep', 'dracula', 'dufte', 'dufte_bar', 'duftify', 'github', 'gruvbox', 'nord', 'onedark', 'pacoty', 'pitaya_smoothie', 'solarized', 'tab10', 'tab20', 'tab20r', 'tokyo_night'等,部分主题还包含'dark'、'light'等可选,不一一举例了。


matplotx.line_labels()

可轻松为折线图添加标签,整合了dufte包,

import numpy as np
import matplotlib.pyplot as plt
import matplotx
mpl.rc_file_defaults()
plt.figure(dpi=100)
plt.style.use(matplotx.styles.tokyo_night['day'])
plt.plot(np.arange(5.0, 10.0, 0.02),
         np.cos(2 * np.pi * np.arange(0.0, 5.0, 0.02)),label='label_1')
plt.plot(np.arange(5.0, 10.0, 0.02),
         np.cos(2 * np.pi * np.arange(0.0, 5.0, 0.02))+0.5,label='label_2')

matplotx.line_labels()#为折线添加标签

plt.title("matplotx.line_labels()", size=15)
plt.show()


matplotx.show_bar_values()

bar图轻松添加标签,

import numpy as np
import matplotlib.pyplot as plt
import matplotx

mpl.rc_file_defaults()
plt.style.use(matplotx.styles.pitaya_smoothie['light'])
plt.bar([1, 2, 3], [1, 1, 2])

matplotx.show_bar_values("{:.2f}")#matplotx.show_bar_values

plt.title("matplotx.show_bar_values", size=15)
plt.show()


matplotx.contours()


matplotx.spy()

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>