【发布时间】:2017-10-21 13:56:52
【问题描述】:
我正在尝试在 jupyter notebook 中制作一个交互式脚本,该脚本将循环绘制不同的图像并要求用户做出决定。我到了可以用 3 个子图重绘图形的地步,但不知道如何配置交互式图形的大小以使所有子图可见。如您所见,第二个子图只有一部分从右侧向外窥视。
如果有任何帮助,我将不胜感激。
这是我的代码:
import cv2
import matplotlib.pyplot as plt
import pandas as pd
% matplotlib notebook
fig, [ax1, ax2, ax3] = plt.subplots(1,3, figsize=(5, 5))
ax1.set_xlabel("src")
ax2.set_xlabel("rgb")
ax3.set_xlabel("hsv")
ax2.set_xlim([-1,257])
ax3.set_xlim([-1,257])
plt.legend(loc='upper right')
color = ('r','g','b') # HSV colors
labels = ('h', 's', 'v')
plt.subplots_adjust(right = 2.3)
for i in range(0,3):
im = cv2.imread("image.png")
im_rgb = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
im_hsv = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)
ax1.imshow(im_rgb, cmap='gray')
for i,col in enumerate(color):
histr = cv2.calcHist([im_rgb],[i],None,[256],[0,256])
ax2.plot(histr, color = col, label=col)
for i,col in enumerate(color):
histr = cv2.calcHist([im_hsv],[i],None,[256],[0,256])
ax3.plot(histr, color = col, label=labels[i])
fig.canvas.draw()
answer = input("Next? " )
【问题讨论】:
-
不,不是,我现在会更正。
标签: python matplotlib jupyter-notebook