matplotlib实现三维柱状图

 import cv2

 img = cv2.imread("1.png", 0)

 #特征点在图片中的坐标位置
m = 448
n = 392 import numpy as np
import matplotlib.pyplot as plt # This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import # setup the figure and axes
fig = plt.figure(figsize=(10, 5)) # 画布宽长比例
ax1 = fig.add_subplot(121, projection='3d')
ax2 = fig.add_subplot(122, projection='3d')
ax1.set_title('Shaded')
ax2.set_title("colored") # fake data
_x = np.arange(444, 453)
_y = np.arange(388, 397)
_xx, _yy = np.meshgrid(_x, _y)
x, y = _xx.ravel(), _yy.ravel()#ravel扁平化
# 函数
top = []
for i in range(-4, 5):
for j in range(-4, 5):
top.append(img[i+n][j+m]) bottom = np.zeros_like(top)#每个柱的起始位置
width = depth = 1#x,y方向的宽厚 ax1.bar3d(x, y, bottom, width, depth, top, shade=True) #x,y为数组 ax1.set_xlabel('X')
ax1.set_ylabel('Y')
ax1.set_zlabel('pixel value') for i in range(-4, 5):
for j in range(-4, 5):
z = img[i+n][j+m] #该柱的高
color = np.array([255, 255, z])/255.0#颜色 其中每个元素在0~1之间
ax2.bar3d(j+m, i+n, 0, width, depth, z, color=color) #每次画一个柱 ax2.set_xlabel('X')
ax2.set_ylabel('Y')
ax2.set_zlabel('pixel value')
plt.show()

以上程序将特征点周围四个像素的像素点三维化,ax1用数组的方式画柱状图,同时绘制多个柱。ax2用数值的方式画柱状图,每次画一个柱。

结果:

matplotlib实现三维柱状图的更多相关文章

  1. Python学习(一) —— matplotlib绘制三维轨迹图

    在研究SLAM时常常需要对其输出的位姿进行复现以检测算法效果,在ubuntu系统中使用Python可以很好的完成相关的工作. 一. Ubuntu下Python的使用 在Ubuntu下使用Python有 ...

  2. Python使用matplotlib绘制三维曲线

    本文主要演示如何使用matplotlib绘制三维图形 代码如下: # -*- coding: UTF-8 -*- import matplotlib as mpl from mpl_toolkits. ...

  3. 机器学习-Matplotlib绘图(柱状图,曲线图,点图)

    matplotlib 作为机器学习三大剑客之一   ,比热按时无比强大的 matplotlib是绘图库,所以呢我就分享一下简单的绘图方式 #柱状图 #导报 柱状图 import matplotlib. ...

  4. 使用matplotlib 制图(柱状图、箱型图)

    柱状图: import pandas as pd import matplotlib.pyplot as plt data = pd.read_csv('D:\\myfiles\\study\\pyt ...

  5. matplotlib绘制三维图

    本文参考官方文档:http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html 起步 新建一个matplotlib.figure.Figure对象, ...

  6. matplotlib表面三维图

    1.basic numpy.meshgrid 由一维数组到二维数组,用于生成网格数据 matplotlib python绘图库 2.code In [88]: from mpl_toolkits.mp ...

  7. 用Matplotlib画三维图片的一个实例

    from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np from matp ...

  8. matplotlib 中的柱状图

    def drawBar(): pyplot.bar(range(5),[100,200,300,400,400]) pyplot.xticks(range(5),['A','B','C','D','E ...

  9. matplotlib 柱状图 Bar Chart 样例及参数

    def bar_chart_generator():     l = [1,2,3,4,5]     h = [20, 14, 38, 27, 9]     w = [0.1, 0.2, 0.3, 0 ...

随机推荐

  1. workerman使用

    1.start_timer.php(boc) <?php use \Workerman\Worker; use \Workerman\Lib\Timer; require_once '/var/ ...

  2. Mint UI 之 Swipe 组件

    #为什么不显示内容? 一定要指定 mt-swipe 元素的宽和高. <mt-swipe :auto="4000" class="swipe"> &l ...

  3. 匹配数字、字母和?%&=-_这几个符号的正则表达式

    /^[\w\?%&=\-_]+$/ 说明:(1) \w 代表 0-9a-zA-Z 即数字.字母 (2) \?%&=\-_ 匹配?%&=-_,而正则中?代表0个或1个,因为是特殊 ...

  4. easyui datagrid 分页 客户分页

    1.写好json 数据 {                                                              "total":21,     ...

  5. Linux的简单介绍和开发基本运维时候用到的命令

    先简单介绍下Linux文件夹目录 1./ linux下的根目录 实际上等同于window的我的电脑点进去 2./etc /usr 一个是系统配置文件存放的地方,一个是系统资源(应用程序)放的地方这俩文 ...

  6. 第二章:冠词(Les articles)

    ★定冠词(Les articles définis ): 阳性单数:le(l') 阴性单数:la(l') 阴阳性复数:les ()表示前面已经提到的人或事物: ()有关的名词已被其它的成分(补语,关系 ...

  7. python3.4用循环往mysql5.7中写数据并输出

    #!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" """ pyt ...

  8. LVDS_IP仿真分析

    这个一个对tx_outclock移相180度后的仿真结果. tx_outclock的时钟沿与数据中心对齐. tx_coreclock时钟与inclock时钟频率相等,但有相差.

  9. java web eclipse中项目的加载过程

    java web eclipse中项目的加载过程: Tomcat默认从WEB-INF/目录下加载资源,Eclipse在发布程序的时候,并没有把User Libraries的相关资源拷贝到WEB-INF ...

  10. Docker load与Docker import

    docker load与docker import   首先,想要清楚的了解docker load与docker import命令的区别,就必须了解镜像与容器的区别: 镜像:用来启动容器的只读模板,是 ...