Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the figure size of a seaborn axes or figure level plot

How do I change the size of my image so it's suitable for printing?

For example, I'd like to use to A4 paper, whose dimensions are 11.7 inches by 8.27 inches in landscape orientation.

like image 612
Michael Grazebrook Avatar asked Jul 23 '15 17:07

Michael Grazebrook


People also ask

How do you change the size of a figure in Python?

If you've already got the figure created, say it's 'figure 1' (that's the default one when you're using pyplot), you can use figure(num=1, figsize=(8, 6), ...) to change it's size etc. If you're using pyplot/pylab and show() to create a popup window, you need to call figure(num=1,...)


2 Answers

You can also set figure size by passing dictionary to rc parameter with key 'figure.figsize' in seaborn set method:

import seaborn as sns  sns.set(rc={'figure.figsize':(11.7,8.27)}) 

Other alternative may be to use figure.figsize of rcParams to set figure size as below:

from matplotlib import rcParams  # figure size in inches rcParams['figure.figsize'] = 11.7,8.27 

More details can be found in matplotlib documentation

like image 173
student Avatar answered Oct 20 '22 17:10

student


You need to create the matplotlib Figure and Axes objects ahead of time, specifying how big the figure is:

from matplotlib import pyplot import seaborn  import mylib  a4_dims = (11.7, 8.27) df = mylib.load_data() fig, ax = pyplot.subplots(figsize=a4_dims) seaborn.violinplot(ax=ax, data=df, **violin_options) 
like image 25
Paul H Avatar answered Oct 20 '22 17:10

Paul H