How to Change the Figure Size of a Seaborn Axes or Figure Level Plot

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

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)

How do I change the plot size for a seaborn scatter plot?

height and aspect arguments could be used to change plot size.
This code may works:

sns.relplot(data = apartamentos, x = "Area", y = "Preco",
height = 8, aspect = 1.25)

Changing Seaborn figure size

You are making two figures, with the call to plt.figure and plt.subplots. You are setting the size only on the first figure, but you are using the second figure to draw your barplot.

How to edit figure size in seaborn plot

Use pyplot.subplots; change

fig = plt.figure()
ax0 = fig.add_subplot(121)
ax1 = fig.add_subplot(122)

to something like

fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(10, 10))

adjusting the figsize as desired.

How to change the size of image created by savefig (seaborn heatmap ) to 1000*1000 px?

plt.subplots_adjust(left=0, bottom=0, right=1, top=1) would reduce the whitespace. plt.axis('off') turns off the axes.

Also note that figsize=(1,1) might give strange results when working with text. figsize=(10,10) and plt.savefig(..., dpi=100) could work better.

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy.ndimage import gaussian_filter

w = 1000
h = 1000
plt.figure(figsize=(w / 100, h / 100))
ax = sns.heatmap(gaussian_filter(np.random.rand(50, 50), 5), xticklabels=False, yticklabels=False, cbar=False)
plt.subplots_adjust(left=0, bottom=0, right=1, top=1)
plt.axis('off')
plt.savefig('tempFile.png', dpi=100, pad_inches=0)

1000x1000 bitmap



Related Topics



Leave a reply



Submit