EmJ
EmJ

Reputation: 4618

How to make labels look normal in seaborn in python?

I am trying to plot a barplot using seaborn. My code is as follows.

mylist_new = [['1988', 365616], ['1989', 381407], ['1990', 388191], ['1991', 388799], ['1992', 391830], ['1993', 398131], ['1994', 407339], ['1995', 416508], ['1996', 421856], ['1997', 432077], ['1998', 446892], ['1999', 459833], ['2000', 485517], ['2001', 505798], ['2002', 521728], ['2003', 549363]]
df = pd.DataFrame(mylist_new, columns=["year", "values"])
df["newvalues"] = df["values"].cumsum()
sns.set(style="whitegrid")
sns.barplot(x="year",y="newvalues",data=df, label='big')

However the plot I get is as follows. In other words, the labels of the plot is very small.

enter image description here

I am wondering if there is a way in seaborn to make the labels look in normal size?

EDIT:

Suppose if mylist_new is as follows.

mylist_new = [['1999', 459833], ['2000', 485517], ['2001', 505798], ['2002', 521728], ['2003', 549363], ['2004', 579103], ['2005', 609911], ['2006', 634697], ['2007', 657782], ['2008', 686164], ['2009', 708009], ['2010', 735288], ['2011', 769720], ['2012', 811656]]

My plot looks like below. If you closely see the values in y-axis, you can see that the values are no lonfer in the format of 100000. They have transformed into decimal values. Is there a way to keep them as they were before?

enter image description here

My code is as follows.

mylist_new = [['1999', 459833], ['2000', 485517], ['2001', 505798], ['2002', 521728], ['2003', 549363], ['2004', 579103], ['2005', 609911], ['2006', 634697], ['2007', 657782], ['2008', 686164], ['2009', 708009], ['2010', 735288], ['2011', 769720], ['2012', 811656]]
df = pd.DataFrame(mylist_new, columns=["year", "values"])
df["newvalues"] = df["values"].cumsum()
sns.set(style="whitegrid")
sns.barplot(x="year",y="newvalues",data=df)
plt.xlabel('year', fontsize=45)
plt.ylabel('new values', fontsize=45)
plt.tick_params(labelsize=45)
plt.xticks(rotation=90);

I am happy to provide more details if needed.

Upvotes: 3

Views: 196

Answers (1)

Arne
Arne

Reputation: 10545

You can use the matplotlib pyplot interface for that. If you increase the size of the x tick labels, you may also want to rotate them by 90 degrees, so that they don't overlap.

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

mylist_new = [['1988', 365616], ['1989', 381407], ['1990', 388191], ['1991', 388799],
              ['1992', 391830], ['1993', 398131], ['1994', 407339], ['1995', 416508],
              ['1996', 421856], ['1997', 432077], ['1998', 446892], ['1999', 459833],
              ['2000', 485517], ['2001', 505798], ['2002', 521728], ['2003', 549363]]
df = pd.DataFrame(mylist_new, columns=["year", "values"])
df["newvalues"] = df["values"].cumsum()
sns.set(style="whitegrid")
sns.barplot(x="year", y="newvalues", data=df, label='big')

plt.xlabel('year', fontsize=24)
plt.ylabel('new values', fontsize=24)
plt.tick_params(labelsize=20)
plt.xticks(rotation=90);

barplot

Upvotes: 2

Related Questions