👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I am writing a quick-and-dirty script to generate plots on the fly. I am using the code below (from Matplotlib documentation) as a starting point:
from pylab import figure, axes, pie, title, show
# Make a square figure and axes
figure(1, figsize=(6, 6))
ax = axes([0.1, 0.1, 0.8, 0.8])
labels = "Frogs", "Hogs", "Dogs", "Logs"
fracs = [15, 30, 45, 10]
explode = (0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels, autopct="%1.1f%%", shadow=True)
title("Raining Hogs and Dogs", bbox={"facecolor": "0.8", "pad": 5})
show() # Actually, don"t show, just save to foo.png
I don"t want to display the plot on a GUI, instead, I want to save the plot to a file (say foo.png), so that, for example, it can be used in batch scripts. How do I do that?
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from Save plot to image file instead of displaying it using Matplotlib, check other code Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Save plot to image file instead of displaying it using Matplotlib
- Deutsch Save plot to image file instead of displaying it using Matplotlib
- Français Save plot to image file instead of displaying it using Matplotlib
- Español Save plot to image file instead of displaying it using Matplotlib
- Türk Save plot to image file instead of displaying it using Matplotlib
- Русский Save plot to image file instead of displaying it using Matplotlib
- Português Save plot to image file instead of displaying it using Matplotlib
- Polski Save plot to image file instead of displaying it using Matplotlib
- Nederlandse Save plot to image file instead of displaying it using Matplotlib
- 中文 Save plot to image file instead of displaying it using Matplotlib
- 한국어 Save plot to image file instead of displaying it using Matplotlib
- 日本語 Save plot to image file instead of displaying it using Matplotlib
- हिन्दी Save plot to image file instead of displaying it using Matplotlib
Warsaw | 2023-02-01
I was preparing for my coding interview, thanks for clarifying this - Save plot to image file instead of displaying it using Matplotlib in Python is not the simplest one. Will get back tomorrow with feedback
New York | 2023-02-01
I was preparing for my coding interview, thanks for clarifying this - Save plot to image file instead of displaying it using Matplotlib in Python is not the simplest one. I just hope that will not emerge anymore
Prague | 2023-02-01
I was preparing for my coding interview, thanks for clarifying this - Save plot to image file instead of displaying it using Matplotlib in Python is not the simplest one. Checked yesterday, it works!