我使用Python matplotlib来绘制函数,并且我知道如何在不同的子图中绘制几个函数,就像这个图,

在处理图像时,我使用imshow()来绘制图像,但是如何用一个图形在不同的子图中绘制多个图像呢?
发布于 2013-06-14 15:05:51
文档提供了一个示例(页面下降约四分之三):
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
fig = plt.figure()
a=fig.add_subplot(1,2,1)
img = mpimg.imread('../_static/stinkbug.png')
lum_img = img[:,:,0]
imgplot = plt.imshow(lum_img)
a.set_title('Before')
plt.colorbar(ticks=[0.1,0.3,0.5,0.7], orientation ='horizontal')
a=fig.add_subplot(1,2,2)
imgplot = plt.imshow(lum_img)
imgplot.set_clim(0.0,0.7)
a.set_title('After')
plt.colorbar(ticks=[0.1,0.3,0.5,0.7], orientation='horizontal')
# ---------------------------------------
# if needed inside the application logic, uncomment to show the images
# plt.show()基本上,这与您通常使用fig.add_subplot创建轴时一样.
发布于 2019-02-25 16:09:03
简单的python代码,可以在图形中绘制子图;
rows=2
cols=3
fig, axes = plt.subplots(rows,cols,figsize=(30,10))
plt.subplots_adjust(wspace=0.1,hspace=0.2)
features=['INDUS','RM', 'AGE', 'DIS','PTRATIO','MEDV']
plotnum=1
for idx in features:
plt.subplot(rows,cols,plotnum)
sns.distplot(data[idx])
plotnum=plotnum+1
plt.savefig('subplots.png')通过下面的链接获取更详细的https://exploredatalab.com/how-to-plot-multiple-subplots-in-python-with-matplotlib/
https://stackoverflow.com/questions/17111525
复制相似问题