The Sage
The Sage

Reputation: 93

Tight layout in seaborn

Quite new to data science, I'm trying to make a graph using catplot but the text in the x-axis keeps overlapping. How do implement tight layout? I found a few descriptions online but it didn't make any sense.

import csv
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
i=0
df = pd.DataFrame()
with open("D:/france.csv", 'r') as csvFile:
    reader = csv.reader(csvFile)
    for row in reader:
df=df.append({'TIME':row[0],'GEO':row[1],'UNIT':row[2],'SEX':row[3],'AGE':row[4],'ICD10':row[5],'Value':row[6],'flags and footnotes':row[7]},ignore_index=True)
df1=df[1:]

fig=sns.catplot(x="TIME",y="ICD10",data=df1)
csvFile.close()

Warning: UserWarning: Tight layout not applied. The left and right margins cannot be made large enough to accommodate all axes decorations. warnings.warn('Tight layout not applied. The left and right margins '

Upvotes: 5

Views: 20522

Answers (1)

Stefano
Stefano

Reputation: 137

To apply tight layout you can simply use:

plt.tight_layout()
plt.show()

at the end of your code.

Maybe what do you want to do here is to made the axis longer increasing the size of the plot, or reduce the size of the character. With fig=plt.figure(figsize=(1,1)) before calling sns.catplot you can set the size of the figure, for example.

Upvotes: 9

Related Questions