辅助Matplotlib轻松实现理想图形。matplotx整合了多种可视化主题,比Matplotlib内置主题优美,例如,
xx主题名称调用;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'等可选,不一一举例了。
可轻松为折线图添加标签,整合了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()
为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()
ref:https://github.com/nschloe/matplotx
分享
点收藏
点点赞
点在看
文章转发自AI科技大本营微信公众号,版权归其所有。文章内容不代表本站立场和任何投资暗示。
Copyright © 2021.Company 元宇宙YITB.COM All rights reserved.元宇宙YITB.COM