[更新]我找到了更多示例,我现在可以做到了 Can I plot several histograms in 3d?
我知道这个问题已经问过,我试试这个How to calculate 3D histogram in python using open CV但是它不起作用
我想要这样的事情3D histogram
这就是我现在所拥有的My Graph
Sub Transfer(x As Long)
Dim Rng, ID as Range
Dim i, j, n As Long
Worksheets(5).Activate
n = Worksheets(5).Range(Range("I88"), Range("I88").End(xlToRight)).Count
Worksheets(x).Select
Set Rng = Worksheets(3).UsedRange.Find("Element", LookIn:=xlValues).Offset(1, 1)
Set ElemID = Range(ElemRng.Offset(0, -1), ElemRng.Offset(0, -1).End(xlDown))
Set ElemRng = Worksheets(3).Range(ElemRng, ElemRng.End(xlToRight))
End Sub
我可以使用plt.hist()绘制3d条形图或者我还需要更多东西吗?
我一直在寻找图像教程的3d直方图,但我找不到任何
答案 0 :(得分:3)
代码:
#!/usr/bin/python3
# 2017.12.20 14:00:12 CST
# 2017.12.20 14:26:08 CST
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import cv2
img = cv2.imread("panda.png")
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h,s,v = cv2.split(hsv)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for x, c, z in zip([h,s,v], ['r', 'g', 'b'], [30, 20, 10]):
xs = np.arange(256)
ys = cv2.calcHist([x], [0], None, [256], [0,256])
cs = [c] * len(xs)
cs[0] = 'c'
ax.bar(xs, ys.ravel(), zs=z, zdir='y', color=cs, alpha=0.8)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()