将jpeg图像与图形相结合

时间:2014-10-18 20:49:19

标签: python image matplotlib subplot

我正在尝试将jpg图像与-1到1之间的连续线的简单子图组合 但我还没有管理它。问题是jpg图像正在加载3维(RGB),而图形只能接受具有两个维度的数组。

任何想法??

提前完成

到目前为止,我通过在线搜索来管理这个:

fig, axes = plt.subplots(nrows=2)
print fig,axes
for ax in axes:
    ax.plot(np.random.random(100))

image=im.imread('image.jpg')
plot = plt.imshow(image)

plt.text(image.shape[1]/2, 10, "Does this refer to a ?", horizontalalignment = "center")

axes[1].autoscale(False))



plt.show()

1 个答案:

答案 0 :(得分:1)

我无法理解您的问题。

这样做你想要的吗?

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as im

fig, (chart, picture) = plt.subplots(nrows=2)

# First, the chart
chart.plot(np.random.random(100))

# Second, an image
image=im.imread('image.jpg')
picture.imshow(image)
picture.axis('off')

plt.show()

enter image description here