Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change figure size and figure format in matplotlib [duplicate]

I want to obtain fig1 exactly of 4 by 3 inch sized, and in tiff format correcting the program below:

import matplotlib.pyplot as plt  list1 = [3,4,5,6,9,12] list2 = [8,12,14,15,17,20]  plt.plot(list1, list2) plt.savefig('fig1.png', dpi = 300) plt.close() 
like image 286
golay Avatar asked Jun 14 '13 13:06

golay


People also ask

How do I change a figure in Matplotlib?

Change Figure Format in Matplotlib To change the figure format, we can change the image file's extension in the savefig() method. We can save plots in different formats like png , jpg , svg , pdf , and many more. This saves the figure in the jpg format.

How do I change the size of a figure in pandas plot?

The size of a plot can be modified by passing required dimensions as a tuple to the figsize parameter of the plot() method. it is used to determine the size of a figure object. Where dimensions should be given in inches.


1 Answers

You can set the figure size if you explicitly create the figure with

plt.figure(figsize=(3,4)) 

You need to set figure size before calling plt.plot() To change the format of the saved figure just change the extension in the file name. However, I don't know if any of matplotlib backends support tiff

like image 163
Francesco Montesano Avatar answered Oct 14 '22 15:10

Francesco Montesano