5

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 '

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
The Sage
  • 93
  • 1
  • 1
  • 4
  • Make your figure bigger? https://stackoverflow.com/questions/31594549/how-do-i-change-the-figure-size-for-a-seaborn-plot But be aware that if your data is infinitely huge, they won't fit on the page for practical page sizes – Jody Klymak Jul 26 '19 at 16:24

1 Answers1

9

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.

Stefano
  • 127
  • 2
  • 12
  • 2
    I think that thight layout is enabled automatically by Seaborn, and that the Warning is about not being able to apply it. I have the same problem and the solution that you proposed doesn't change the warnings. – Gabriele Feb 24 '22 at 12:26