matplotlib学习

编程入门 行业动态 更新时间:2024-10-21 12:38:18

<a href=https://www.elefans.com/category/jswz/34/1769675.html style=matplotlib学习"/>

matplotlib学习

import matplotlib.pyplot as plt

import numpy as np

n = 12

X = np.arange(n)

Y1 = (1-X/float(n))*np.random.uniform(0.5,1.0,n)

Y2 = (1-X/float(n))*np.random.uniform(0.5,1.0,n)

plt.bar(X,+Y1,facecolor = ‘#9999ff’,edgecolor = ‘white’)
plt.bar(X,-Y2,facecolor = ‘#ff9999’,edgecolor = ‘white’)

for x,y in zip(X,Y1):
# text 加入数值标签
# ha横向对齐方式 center表示居中,va纵向对齐方式,bottom表示置底
# x+0.4,y+0.5,数字标签的位置,利用循环的方式
plt.text(x+0.4,y+0.05,’%.2f’%y,ha = ‘center’,va=‘bottom’)

for x, y in zip(X, Y2):
plt.text(x + 0.4, -y - 0.05, ‘-%.2f’ % y, ha=‘center’, va=‘top’)

plt.xlim(-5,n)
plt.xticks(())
plt.ylim(-1.25,1.25)
plt.yticks(())
plt.show()

更多推荐

matplotlib学习

本文发布于:2024-02-07 02:59:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1752409.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:matplotlib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!