开天辟地--转载 图片按色阶3维呈现

在这里插入代码片
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 20 01:51:11 2020

@author: Administrator
"""

# -- coding: utf-8 -- 
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

import cv2 as cv

img = cv.imread('110.jpg')
 
label_font = {
    'color' : 'c' ,
    'size' : 15,
    'weight' : 'bold'
}
 
def randrange(n, vmin, vmax):
    r = np.random.rand(n)   #随机生成n 个介于0-1之间的数
    return (vmax-vmin) * r + vmin   #得到n个[vmin,vmax]之间的随机数
 
 
fig = plt.figure(figsize=(16,12))   # 参数依然是图片大小
ax = fig.add_subplot(111, projection='3d')      #确定子坐标轴,111表示1行1列的第一个图   要同时画好几个图的时候可以用这个
 
#准备数据

#for zlow, zhigh, c, m, l in [(4, 15, 'r', 'o', 'posirtive'), (13, 40, 'g', '*', 'negative')]:  #用两个tuple(画笔),是为了将形状和颜色区别开来

for x in range(300):
    for y in range(300):
        z=img[x,y,0]
        
        ax.scatter(x, y, z, c='g', marker='.', s=1)   # marker的尺寸和z的大小成正比 label=l, s=z * 10

ax.set_xlabel("X axis", fontdict=label_font)
ax.set_ylabel("Y axis", fontdict=label_font)
ax.set_zlabel("Z axis", fontdict=label_font)
ax.set_title("Scatter plot", alpha=0.6, color="b", size=25, weight='bold', backgroundcolor="y")   #子图(其实就一个图)的title
ax.legend(loc="upper left")   #legend的位置位于左上
 
 
plt.show()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值