首页 > 其他分享 >Matplotlib数据可视化——bar柱状图

Matplotlib数据可视化——bar柱状图

时间:2022-11-22 14:32:13浏览次数:32  
标签:plt bar center text random Matplotlib 柱状图 Y1

不知道为什么第四象限的数字位置不是我所期望的,望看到的大佬赐教
几个要点:

  • 函数原型: numpy.random.uniform(low,high,size)功能:从一个均匀分布[low,high)中随机采样,注意定义域是左闭右开,即包含low,不包含high.
  • zip() 函数用于将可迭代的对象作为参数,将对象中对应的元素打包成一个个元组,然后返回由这些元组组成的对象。可以使用list转换输出列表
  • 关于matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=False, **kwargs)查看官方文档如下:
    • x, y:表示坐标;
    • s:字符串文本;
    • fontdict:字典,可选;
    • kw:
      • fontsize=12,
      • horizontalalignment=‘center’、ha=’center’
      • verticalalignment=’center’、va=’bottom’
    • fig.text()(fig = plt.figure(…))
    • ax.text()(ax = plt.subplot(…))
      demo如下
n = 12
X = np.arange(n)
Y1= (1-X/n)*np.random.uniform(0.5, 1.0, n)
Y2= (1-X/n)*np.random.uniform(0.5, 1.0, n)

plt.bar(X, +Y1, facecolor='#9999ff', edgecolor='white')
plt.bar(X, -Y1,)

for x, y in zip(X ,Y1):
    plt.text(x, y+0.01, '%.2f' % y, ha='center', va='bottom')

for x, y in zip(X ,Y2):
    plt.text(x, -y-0.01, '-%.2f' % y, ha='center', va='top')

plt.show()

Matplotlib数据可视化——bar柱状图_python

标签:plt,bar,center,text,random,Matplotlib,柱状图,Y1
From: https://blog.51cto.com/u_13875041/5877990

相关文章

  • WordpressCMS主题开发06-分类页面的文章调用和sidebar制作
    这节课,我们来学习cms制作的第6课程,制作分类页面category.php以及分类页面的sidebar。我们先来查看静态页面list.html,如果我们要做这个页面,其实已经做好了header以及footer。......
  • 简单的可视化图表——“柱状图”
    ECharts柱状图基础模板参考:https://echarts.apache.org/handbook/zh/get-started/例图:下附简单代码:letoption={//1.鼠标移入tooltip:{......
  • echarts 立体柱状图
     echarts立体柱状图option={"grid":{"top":"0%","bottom":"8%","right":"0%","left":"0%"},"xAxis":{......
  • 84.柱状图中最大的矩形 largest-rectangle-in-histogram
    问题描述84.柱状图中最大的矩形解题思路首先,要找最大矩形,即要找每个heights[i]所能构成的矩形面积的最大值:heights[i]所能构成的最大矩形,左侧,右侧必定都是连续的大于......
  • echarts柱状图经验
    涉及知识点1.动态单位,以及单位的及时变化2.窗口变化,重新渲染echarts3.tooltips自定义4.Y轴刻度过长的处理相关代码<template><divclass="usageAll"><route......
  • matplotlib 中的 figure/ax/plt的区别
    知其然也要知其所以然matplotlibhasanextensivecodebasethatcanbedauntingtomanynewusers.However,mostofmatplotlibcanbeunderstoodwithafairly......
  • 152. Maximum Product Subarray
    Givenanintegerarray nums,finda subarray thathasthelargestproduct,andreturn theproduct.Thetestcasesaregeneratedsothattheanswerwillfit......
  • python可视化——matplotlib画图颜色控制
    个人认为这篇文章介绍的非常详细,值得推荐python可视化——matplotlib画图颜色控制_CD_Don的博客-CSDN博客......
  • matplotlib安装
    1.安装matplotlibpython-mpipinstall--usermatplotlib 2.安装失败请求超时,我们换国内的镜像文件。 pipinstall-ihttps://pypi.tuna.tsinghua.edu.cn/......
  • 下载数据(matplotlib可视化16章-1)
    1、从CSV文件中提取数据importcsvimportmatplotlib.pyplotaspltfilename='sitka_weather_07-2014.csv'withopen(filename)asf:reader=csv.reader(f......