文章目录

  • [参考文章1:Python 绘制 柱状图](https://www.cnblogs.com/shenxiaolin/p/11100094.html)
  • 我的代码

参考文章1:Python 绘制 柱状图

# 创建一个点数为 8 x 6 的窗口, 并设置分辨率为 80像素/每英寸
plt.figure(figsize=(10, 10), dpi=80)
# 再创建一个规格为 1 x 1 的子图
# plt.subplot(1, 1, 1)
# 柱子总数
N = 10
# 包含每个柱子对应值的序列
values = (56796,42996,24872,13849,8609,5331,1971,554,169,26)
# 包含每个柱子下标的序列
index = np.arange(N)
# 柱子的宽度
width = 0.45
# 绘制柱状图, 每根柱子的颜色为紫罗兰色
p2 = plt.bar(index, values, width, label="num", color="#87CEFA")
# 设置横轴标签
plt.xlabel('clusters')
# 设置纵轴标签
plt.ylabel('number of reviews')
# 添加标题
plt.title('Cluster Distribution')
# 添加纵横轴的刻度
plt.xticks(index, ('mentioned1cluster', 'mentioned2cluster', 'mentioned3cluster', 'mentioned4cluster', 'mentioned5cluster', 'mentioned6cluster', 'mentioned7cluster', 'mentioned8cluster', 'mentioned9cluster', 'mentioned10cluster'))
# plt.yticks(np.arange(0, 10000, 10))
# 添加图例
plt.legend(loc="upper right")
plt.show()

我的代码

# -*- coding: utf-8 -*-
"""
@File    : 测试拟合平面.py
@Time    : 2020/9/8 9:23
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from numba import jit# 加载数据
def load_data(file_path):# 读取数据npzfile = np.load(file_path)# x, y, z = npzfile['arr_0'], npzfile['arr_1'], npzfile['arr_2']return npzfile['x'], npzfile['y'], npzfile['z']# 计算拟合片面
def cal_flat(x_, y_, z_):# 取样点数量point_num = len(x_)print('len={}'.format(point_num))# 创建系数矩阵Aa = 0A = np.ones((point_num, 3))for i in range(0, point_num):A[i, 0] = x_[a]A[i, 1] = y_[a]a = a + 1# print(A)# 创建矩阵bb = np.zeros((point_num, 1))a = 0for i in range(0, point_num):b[i, 0] = z_[a]a = a + 1# print(b)# 通过X=(AT*A)-1*AT*b直接求解A_T = A.TA1 = np.dot(A_T, A)A2 = np.linalg.inv(A1)A3 = np.dot(A2, A_T)X = np.dot(A3, b)print('平面拟合结果为:z = %.6f * x + %.6f * y + %.6f' % (X[0, 0], X[1, 0], X[2, 0]))# 计算方差R = 0for i in range(0, point_num):R = R + (X[0, 0] * x_[i] + X[1, 0] * y_[i] + X[2, 0] - z_[i]) ** 2print('方差为:%.*f' % (3, R))return X# 绘制三维深度散点图及拟合平面
def show_flat(X):# 展示图像fig1 = plt.figure()ax1 = fig1.add_subplot(111, projection='3d')ax1.set_xlabel("x")ax1.set_ylabel("y")ax1.set_zlabel("z")# ax1.scatter(x, y, z, c='r', marker='o')ax1.scatter(x, y, z, c='r', marker='.')x_p = np.linspace(-200, 1480, 168)y_p = np.linspace(-200, 920, 112)x_p, y_p = np.meshgrid(x_p, y_p)z_p = X[0, 0] * x_p + X[1, 0] * y_p + X[2, 0]ax1.plot_wireframe(x_p, y_p, z_p, rstride=10, cstride=10)plt.show()# 计算深度误差
def cal_error_distribution(x_, y_, z_, coefficient_):# 计算误差error = z_ - (coefficient_[0, 0] * x_ + coefficient_[1, 0] * y_ + coefficient_[2, 0])return error# 统计各个区间误差的数量
def count_error_number(depth_error_, column_num):# 提取负向最大深度误差和正向最大深度误差error_max = np.max(depth_error)# print(error_max)    # 23.39967553034205error_min = np.min(depth_error)# print(error_min)  # -18.65760653439031# 柱子宽度error_width = (error_max - error_min) / column_num# print(column_width) # 1.6822912825892944# 创建柱子高度序列column_height_sequence = np.zeros(column_num)# 统计每个柱子包含深度点的数量for error in depth_error_:index = int((error - error_min) // error_width)# 当深度误差error等于最大深度误差的时候,下标会溢出,所以要加个判断限制一下if index == column_num:# print(dep)  # 23.39967553034205index -= 1column_height_sequence[index] += 1# print(column_height_sequence)return column_height_sequence# 绘制柱状图
def draw_histogram(column_height_sequence_):# 创建一个点数为 8 x 6 的窗口, 并设置分辨率为 80像素/每英寸plt.figure(figsize=(10, 10), dpi=80)# plt.figure()# 再创建一个规格为 1 x 1 的子图# plt.subplot(1, 1, 1)# 柱子总数N = len(column_height_sequence)# 包含每个柱子对应值的序列values = column_height_sequence_# 包含每个柱子下标的序列index = np.arange(N)# 柱子的宽度width = 1# 绘制柱状图, 每根柱子的颜色为紫罗兰色# p2 = plt.bar(index, values, width, label="num", color="#87CEFA")p2 = plt.bar(index, values, width, label="num", color="#87CEFA")# 设置横轴标签plt.xlabel('error/mm')# 设置纵轴标签plt.ylabel('number of points')# 添加标题plt.title('D435 error Distribution(500mm)')# 添加纵横轴的刻度index_new = []for index_ in index:if index_ % 100 == 0:index_new.append(index_)# print(index_new)index_new_content = []for index in index_new:error_max = np.max(depth_error)error_min = np.min(depth_error)index_new_content.append(error_min + (error_max - error_min) * index / N)index_new_content_string = [str(i) for i in np.around(index_new_content, decimals=1)]# plt.xticks(index, (#     'mentioned1cluster', 'mentioned2cluster', 'mentioned3cluster', 'mentioned4cluster', 'mentioned5cluster',#     'mentioned6cluster', 'mentioned7cluster', 'mentioned8cluster', 'mentioned9cluster', 'mentioned10cluster'))plt.xticks(index_new, index_new_content_string)# plt.yticks(np.arange(0, 10000, 10))# 添加图例plt.legend(loc="upper right")plt.show()if __name__ == '__main__':# 加载数据x, y, z = load_data('./data/500mm/4_1599623292.4111953.npz')# 拟合平面并返回平面函数系数coefficient = cal_flat(x, y, z)# 绘制平面及深度散点# show_flat(coefficient)# 计算深度误差depth_error = cal_error_distribution(x, y, z, coefficient)# 统计各个误差区间的数量(柱状图各个柱子高度)column_height_sequence = count_error_number(depth_error, 1000)# 绘制柱状图draw_histogram(column_height_sequence)


代码中深度数据:
https://download.csdn.net/download/Dontla/12833241

python绘制柱状图,如何改变柱状柱间距,如何设置横纵轴标签(绘制Intel Realsense D435深度误差柱状图)相关推荐

  1. echarts柱状图,改变柱状颜色

    在使用echarts产生的柱状图中,有时候自动产生的颜色大不如人意,可以通过以下参数进行修改. series : [{name:'天数',type:'bar',stack: '天',data:[30, ...

  2. python如何拟合三维平面(拟合Intel Realsense D435深度数据点)

    文章目录 拟合Intel Realsense D435深度数据点 参考文章:[MQ笔记]超简单的最小二乘法拟合平面(Python) import numpy as np import matplotl ...

  3. python Intel Realsense D435 多线程资源分配问题(卡住、卡死)

    在使用python多线程调用Intel Realsense D435多个摄像头时,发现pyrealsense的例如pipeline.start().context.query_devices()函数会 ...

  4. Intel Realsense D435 python multiprocessing 摄像头多进程流传输

    参考文章1:python 测试multiprocessing多进程 参考文章2:Intel Realsense D435 多摄像头目标识别架构

  5. Intel Realsense D435 python (Python Wrapper)examples 官方案例汇总

    From pypi/pyrealsense 1.Intel Realsense D435 python (Python Wrapper)example -1: quick start (快速开始) F ...

  6. python pyusb库使用教程【在window10系统上操作USB】(操作Intel Realsense D435)

    发现位置:usb之python(pyusb) pypi:pyusb 1.0.2 Libraries.io教程 :pyusb Release 1.0.2 github教程:Programming wit ...

  7. Intel Realsense D435 在C/C++中表示的frame_set就是python中的frames?【wait_for_frames()】

    参考文章:Intel Realsense D435 (Python Wrapper)example03: Stream Alignment 流对齐 通过深度去除背景

  8. Intel Realsense D435 python 如何获取(打印)所有摄像头序列号信息?

    import pyrealsense2 as rsctx = rs.context() if len(ctx.devices) > 0:for d in ctx.devices:print('F ...

  9. Intel Realsense D435 python (Python Wrapper)example00: NumPy Integration 将深度帧数据转换为 Numpy 数组进行处理

    NumPy Integration: Librealsense frames support the buffer protocol. A numpy array can be constructed ...

最新文章

  1. cad画流程图的插件_CAD制图太慢?62款辅助插件汇总,款款精品,效率提升80%
  2. AI产业投融资情况回顾、中美科技巨头AI产业投资布局以及领先投资机构AI产业投资布局...
  3. vagrant box php开发环境配置 -- 重新打包发布vagrant box
  4. 利用MEGA32制作辉光数码管显示电路
  5. ansible配置详解及基本示例
  6. Linux命令行模式下的复制和粘贴以及停止命令刷新
  7. 西建大历年电子与通信工程复试真题_历年复试试题回忆
  8. 为什么要进行透明计算和透明计算是什么
  9. 史上最严重的忘拿钥匙事件 | 今日最佳
  10. mysql proxy 悲观锁_mysql悲观锁总结和实践
  11. vue-cli构建的项目手动添加eslint配置
  12. 如何利用URLOS和云存储打造一个不惧怕宕机的网站环境
  13. WINDOWS游戏编程大师技巧-常见编绎连接错误FAQ
  14. OC算法练习-Hash算法
  15. 计算机毕业论文任务书模板,计算机毕业论文设计任务书范文计算机系毕业论文任务书上的方法写.doc...
  16. 手机怎么录游戏视频 手机屏幕录制的方法
  17. openwrt luci固件升级流程
  18. 服务器被攻击怎么封禁IP
  19. 统一告警平台设计方案
  20. paypal IPN and PDT

热门文章

  1. Apache+php+tomcat+mysqlon linxu
  2. DundasWebChart 5.5 破解续.
  3. php curl rst,CURL错误:Recv失败:通过对等方重置连接 - PHP Curl
  4. 苹果7plus电池寿命查询_iPhone真实电池寿命快速检测,比苹果官方测的还准!
  5. shell自动安装mysql_RPM包安装mysql,采用shell脚本实现自动安装、配置与卸载
  6. 为销售范围维护允许的销售凭证
  7. abap 弹出对话框函数POPUP_GET_VALUES的使用方法
  8. SAP根据用户名查姓名
  9. 使用Java调用以WSDL形式发布的web service
  10. VF01开票自动生成会计凭证