本次介绍Matplotlib的优质扩展matplotx
matplotx可​​​辅助Matplotlib​​​轻松实现理想图形。当Matplotlib遇上matplotx_数据续上几篇👇

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

Matplotlib绘图主题(plt.style)大全​​Seaborn图形外观设置


matplotx.styles.xx

​matplotx整合了多种可视化主题​​​,比Matplotlib内置主题优美,例如,当Matplotlib遇上matplotx_github_02当Matplotlib遇上matplotx_折线图_03通过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()

当Matplotlib遇上matplotx_折线图_04再举个例子,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()

当Matplotlib遇上matplotx_折线图_05还有很多优雅主题,如'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()

当Matplotlib遇上matplotx_github_06


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

当Matplotlib遇上matplotx_折线图_07


matplotx.contours()

当Matplotlib遇上matplotx_github_08


matplotx.spy()

当Matplotlib遇上matplotx_数据_09

ref:https://github.com/nschloe/matplotx


当Matplotlib遇上matplotx_数据_10