• 元宇宙:本站分享元宇宙相关资讯,资讯仅代表作者观点与平台立场无关,仅供参考.

当 Matplotlib 遇上 matplotx

  • AI科技大本营
  • 2022年5月30日06时
作者 | pythonic生物人
来源 | pythonic生物人
本次介绍Matplotlib的优质扩展matplotx。matplotx可辅助Matplotlib轻松实现理想图形。

matplotx.styles.xx

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

通过matplotx.styles.xx主题名称调用;
举个例子,matplotx.styles.solarized['dark']
importnumpyasnp
importmatplotlib.pyplotasplt
importmatplotx
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']

importnumpyasnp
importmatplotlib.pyplotasplt
importmatplotx
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包,

importnumpyasnp
importmatplotlib.pyplotasplt
importmatplotx
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图轻松添加标签

importnumpyasnp
importmatplotlib.pyplotasplt
importmatplotx

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

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


往期回顾

介绍Pandas实战中的一些高端玩法


从Python可视化图表中探究王心凌的流量密码


Pandas表格样式设置指南,爆赞!


如何用一行Python代码制作一个GUI?


分享

点收藏

点点赞

点在看

Copyright © 2021.Company 元宇宙YITB.COM All rights reserved.元宇宙YITB.COM