简体   繁体   English

Seaborn tsplot-y轴刻度

[英]Seaborn tsplot - y-axis scale

在此处输入图片说明

import seaborn as sns
import matplotlib.pyplot as plt

sns.tsplot(data = df_month, time = 'month', value = 'pm_local');
plt.show()

Using this code I get this blank plot, I presume because of the scale of the y-axis. 使用此代码,由于y轴的比例,我得到了这个空白图。 I don't know why this is, here are the first 5 rows of my dataframe (which consists of 12 rows - 1 row for each month): 我不知道为什么,这是我数据框的前5行(由12行组成-每个月1行): 在此处输入图片说明

How can I fix this? 我怎样才能解决这个问题?

I think the problem is related to the field unit . 我认为问题与现场unit The function expects in the case of data passed as DataFrame a unit indicated which subject the data belongs to. 在将数据作为DataFrame传递的情况下,该函数期望一个单位指示数据所属的主题。 This function behavior is not obvious for me, but see this example. 此功能行为对我来说并不明显,但请参见此示例。

# Test Data
df = pd.DataFrame({'month': [1, 2, 3, 4, 5, 6], 
                   'value': [11.5, 9.7, 12, 8, 4, 12.3]})

# Added a custom unit with a value = 1
sns.tsplot(data=df, value='value', unit=[1]*len(df), time='month')

plt.show()

You can also use extract a Series and plot it. 您还可以使用提取Series并将其绘制。

sns.tsplot(data=df.set_index('month')['value'])
plt.show()

在此处输入图片说明

I had this same issue. 我有同样的问题。 In my case it was due to incomplete data, such that every time point had at least one missing value, causing the default estimator to return NaN for every time point. 在我的情况下,这是由于数据不完整所致,因此每个时间点至少都有一个缺失值,从而导致默认估算器为每个时间点返回NaN。

Since you only show the first 5 records of your data we can't tell if your data has the same issue. 由于您仅显示数据的前5条记录,因此我们无法确定您的数据是否存在相同的问题。 You can see if the following fix works: 您可以查看以下修复程序是否有效:

from scipy import stats

sns.tsplot(data = df_month, time = 'month',
           value = 'pm_local',
           estimator = stats.nanmean);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM