Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print text before plotting an image (matplotlib/imageio)

I'm pretty new to Python (and really new to using MatPlotLib and imageio), and I was wondering if there was a possibility to first plot an image and then print some text.
What I mean: when you give:

print('Test')
plt.imshow(imageio.imread(<location>))

It first prints the text and then the image, but when you give:

plt.imshow(imageio.imread(<location>))
print('Test')

It still prints the text first.
Is there a solution to this? And if not, is there an alternative way to do this?

like image 272
Jiemie Avatar asked Nov 07 '22 06:11

Jiemie


1 Answers

Use plt.show() after imshow

import matplotlib.pylab as plt 
from numpy import random

Z = random.random((20,20))   # Test data 

plt.imshow(Z, cmap=plt.get_cmap("Spectral"), interpolation='nearest') # Test plot

plt.show()
print("test")

The result:

enter image description here

like image 102
AshlinJP Avatar answered Nov 15 '22 15:11

AshlinJP