[英]How to graph a seaborn lineplot more specifically
给定一个质量 DataFrame df
:
year count
1980 -23
1980 -4
1981 10
1982 0
1982 4
...
2007 27
2008 0
2008 0
2009 -7
2009 5
值首先按year
排序,然后是count
。 (显示的值是任意改变的)
我想想象一下随着year
的增加, count
如何分布不同,这可以通过百分位数 plot 最有效地显示。 但是,由于我的数据是在 DataFrame 中给出的,我认为更可行(坦率地说,更简单)的方法是使用seaborn.lineplot
:
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(figsize=[16,12])
plt.axhline(y=0, color='black', linestyle='dotted')
sns.lineplot(x="year", y="count", ax=ax, data=df, color='red')
返回:
该图在某种程度上起到了一定的作用,尽管我希望显示比单个百分位梯度具有更多的可变性。 (一个很好的例子是下图的 10 个百分位梯度,从这个链接复制: Using percentiles of a timeseries to set color gradient in Python's matplotlib )
我想知道是否有办法使用seaborn.lineplot
来实现如此详细的绘图,如果没有,是否有办法从pandas
ZBA834BA059A9A379459C112E457 数据中做到这一点
一旦您生成了第一个置信区间或仅生成直线,您可以使用matplotlib ,如本文所示创建多个置信区间。
另一个选项是 plot 使用sns.lineplot
在同一个数字上,但我认为 seaborn 不适合这个。 以数据集flights
为例,首先我们 plot 中线或平均线:
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
flights = sns.load_dataset("flights")
fig,ax = plt.subplots(1,1)
sns.lineplot(data=flights, x="year", y="passengers",ax=ax,ci=None,color="black")
然后我们设置一个调色板并继续添加没有线条的波段(设置 linestyle = ''):
cm = sns.color_palette("Blues",9)
for ix,ci in enumerate(range(10,90,10)):
sns.lineplot(data=flights, x="year", y="passengers",
ci = ci,
ax=ax,linestyle='',
hue = ci,palette={ci:cm[ix]})
给出这样的东西:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.