我在 jupyter_notebook 中设置线图样式时陷入困境

问题描述 投票:0回答:1

开门见山:我为

lineplot
编写了代码,但是当我尝试将其样式更改为
"dark"
时,我失败了。

这是我尝试过的代码,请有人更正!

import seaborn as sns
import matplotlib.pyplot as plt
phool = sns.load_dataset("iris")
phool
sns.lineplot(x="petal_length", y="petal_width", data=phool)
plt.title("Flower's bed")

# style changing
sns.set_style("dark")

plt.show()
python jupyter-notebook jupyter-lab line-plot
1个回答
0
投票

在您的情况下,只需运行单元两次(在同一个内核会话中),因为 Jupyter 会记住seaborn 样式。或者更好的是,将

set_style
移到
lineplot
之前:

sns.set_style("dark")

phool = sns.load_dataset("iris")

sns.lineplot(x="petal_length", y="petal_width", data=phool)
plt.title("Flower's bed")

plt.show();

您也可以使用

axes_style
使其暂时:

with sns.axes_style("dark"):
    sns.lineplot(x="petal_length", y="petal_width", data=phool)

输出:

© www.soinside.com 2019 - 2024. All rights reserved.