To plot an image use the image_plot(path)
function.
-
It is recommended to use the
plotsize()
method beforeimage_plot()
, especially for larger images, to initially reduce the image size and so the computational load. -
To plot much faster set the
fast
parameter toTrue
. In this case, the plot dimensions will be locked to the whatever size was previously chosen, and won't adapt to the terminal or subplot size; also any setting method which follows will not have any effect (likexlabel()
,frame()
and so on). -
A curious visual effect is obtained using for example
marker = list("CuteCat")
withstyle = 'inverted'
: try it out! :-) -
Use the parameter
grayscale
to plot in gray-scale. -
To easily manipulate file paths, use the tools described in this section.
-
To plot images beyond the terminal size use the function
plt.limit_size()
, described here, or the app developed here, usingtkinter
. -
To save the result in colors, as an
html
page, use the functionplt.savefig()
, described here.
In this example, a test image is downloaded in the home folder, visualized and finally removed:
import plotext as plt
path = 'cat.jpg'
plt.download(plt.test_image_url, path)
plt.image_plot(path)
plt.title("A very Cute Cat")
plt.show()
plt.delete_file(path)
or directly on terminal:
python3 -c "import plotext as plt; path = 'cat.jpg'; plt.download(plt.test_image_url, path); plt.image_plot(path); plt.title('A very Cute Cat'); plt.show(); plt.delete_file(path)"
More documentation can be accessed with doc.image_plot()
.
To render a GIF image use the function play_gif(path)
. Note that the function show()
is not necessary in this case, as it is called internally.
In this example, a test GIF is downloaded in the home folder, visualized and finally removed:
import plotext as plt
path = 'homer.gif'
plt.download(plt.test_gif_url, path)
plt.play_gif(path)
plt.delete_file(path)
or directly on terminal:
python3 -c "import plotext as plt; path = 'homer.gif'; plt.download(plt.test_gif_url, path); plt.play_gif(path); plt.show(); plt.delete_file(path)"
which will play the following GIF on terminal:
More documentation can be accessed with doc.play_gif()
.