in Education by
I was trying to write a quick-and-dirty script to generate plots easily. For that, I was using the following code (I took it from the Matplotlib documentation): 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 But 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? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
When you are using Save plot you can use specify .savefig() as an extension to the file:- from matplotlib import pyplot as plt plt.savefig('foo.png') plt.savefig('foo.pdf') The use of .savefig() Will give a rasterized or vectorized output respectively, both which could be useful.

Related questions

0 votes
    Can someone tell me any methods change the size of figures drawn with matploatlib? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Create a two 2-D array. Plot it using matplotlib...
asked Apr 24, 2021 in Technology by JackTerrance
0 votes
    I am ploating simple linear regression plot in R and I want to save it as JPEG or PNG file, How can I do ... it is, Is it possible? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I am confused about the usage of string.join(list) instead of list.join(string), for instance see this code: ... reason behind this? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    If I want to save a plot to a PDF file, which of the following is a correct way of doing that? (a) ... Data Analysis of R Programming Select the correct answer from above options...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    I want to encode an image into a string using the base64 module. I've ran into a problem though. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    When I try t display the Plotly graph from python as an image that works fine import plotly.express as px from IPython. ... ='png')))"] Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I create a plot_ly image using: MilesPlotly...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I create a plot_ly image using: MilesPlotly...
asked Jul 6, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: How do I plot two countplot graphs side by side in seaborn? ( ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: How do I plot two countplot graphs side by side in seaborn? ( ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have two lists, same size, one is y_data and one is x_data x_data is a time hh:mm:ss during ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have the data frame that looks like this: Date Visa Mastercard Amex Paypal 1/1/20 0 20 0 0 2/1/20 ... info() Any help is appreciated Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have followed through some of the threads discussing ouput escaping in XSLT but none seesm to address the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have followed through some of the threads discussing ouput escaping in XSLT but none seesm to address the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
...