python - 如何使标签在 python 中的 seaborn 中看起来正常?

标签 python matplotlib plot seaborn visualization

我正在尝试使用 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')

但是我得到的情节如下。换句话说,绘图的标签非常小。

enter image description here

我想知道在 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 格式。它们已经转化为十进制值。有没有办法让它们保持原样?

enter image description here

我的代码如下。

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);

barplot

关于python - 如何使标签在 python 中的 seaborn 中看起来正常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61705626/

相关文章:

Python 导入 matplotlib.pyplot 不起作用

matlab - 在 matplotlib 中显示最大表面?

python - Python 中的 3D 绘图 - 向散点图添加图例

python - 如何在Python Tkinter中管理带边框标签内的间距?

python - 如何使用 pandas 包为 python 制作的子图清除 boxplot 的默认字幕

python - 通过创建模块简化数据库(psycopg2)的使用

python - 具有对数 Y 轴的小平面网格上的线性回归线

python - Bokeh 悬停工具提示可显示来自不同列的数据

python - 在 Pandas 管道中分配

Python导入错误没有循环依赖