0

want to save python matplotlib output to my local folder in computer

my code

fig = plot.figure(figsize=(30, 30))
outer = gridspec.GridSpec(5, 5, wspace=0.2, hspace=0.2)

for i in range(5):
    inner = gridspec.GridSpecFromSubplotSpec(2, 1,subplot_spec=outer[i], wspace=0.1, hspace=0.1)
   #rnd_number = randint(0,len(pred_images))  # for random output
    rnd_number = i
    pred_image = np.array([pred_images[rnd_number]])
    #pred_image = np.array(pred_images)
    pred_class = get_classlabel(loaded_model.predict_classes(pred_image)[0])
    pred_prob = loaded_model.predict(pred_image).reshape(6)
    for j in range(2):
        if (j%2) == 0:
            ax = plot.Subplot(fig, inner[j])
            ax.imshow(pred_image[0])
            ax.set_title(pred_class)
            ax.set_xticks([])
            ax.set_yticks([])
            fig.add_subplot(ax)
        else:
            ax = plot.Subplot(fig, inner[j])
            ax.bar([0,1,2,3,4,5],pred_prob)
            fig.add_subplot(ax)

plot.figure(figsize=(15,15))
#fig.show()

after executing the above code

after executing the above code iam getting this output

now i want output to save it on computer in particular folder

1 image along with its graphs ie under it in 1 jpg file 2 image along with its graphs ie under it in 2 jpg file

in same i want it to do for all image

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712

1 Answers1

0

Same question is answered already sometimes back.
Requesting you to please check This Link
Still in very general manner, you can go ahead like below.
In your case I am assuming you imported matplotlib library as "plot"

fig = plot.figure(figsize=(30, 30))
....Your Code...
fig.savefig('path/to/save/image/to.png')
  • i have gone through post you have mention but my problem is little different ie-------------- 1 image along with its graphs ie under it in 1 jpg file -- 2 image along with its graphs ie under it in 2 jpg file in same i want it to do for all image – shrey sawhney Nov 19 '19 at 08:27