我正在尝试使用 seaborn 绘制条形图。我的代码如下。
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')
但是我得到的情节如下。换句话说,绘图的标签非常小。
我想知道在 seaborn 中是否有办法让标签看起来像正常大小?
编辑:
假设mylist_new
如下。
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]]
我的情节如下所示。如果仔细查看 y 轴中的值,您会发现这些值不再采用 100000
格式。它们已经转化为十进制值。有没有办法让它们保持原样?
我的代码如下。
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);
如果需要,我很乐意提供更多详细信息。
最佳答案
您可以为此使用 matplotlib pyplot 接口(interface)。如果增加 x 刻度标签的大小,您可能还想将它们旋转 90 度,这样它们就不会重叠。
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);
关于python - 如何使标签在 python 中的 seaborn 中看起来正常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61705626/