2016-09-19 3 views
1

У меня есть фрейм данных под названием amounts_month такого типа:Seaborn tsplot не показывает ничего

product accounting_month amount 
0 A  201404    204748.0 
1 A  201405    445064.0 
2 B  201404    649326.0 
3 B  201405    876738.0 
4 C  201404    1046336.0 

Но когда я оцениваю

import seaborn as sns 
import matplotlib.pyplot as plt 

sns.tsplot(data=amounts_month, 
      time='accounting_month', 
      value='amount', 
      condition='product' 
     ) 

я получаю пустой участок. Что случилось с моим кодом?

ответ

3

Вы можете попробовать добавить еще один данные для продукта C

product accounting_month amount 
A  201404   204748.0 
A  201405   445064.0 
B  201404   649326.0 
B  201405   876738.0 
C  201404   1046336.0 
C  201405   1046336.0 

затем попробуйте следующий код:

import seaborn as sns 
import matplotlib as mpl 
#change the `accounting_month` to datatime 
amounts_month['accounting_month']= pd.to_datetime(amounts_month['accounting_month'], format="%Y%m") 

fig, ax = plt.subplots() 
sns.tsplot(data=amounts_month, 
      time='accounting_month', 
      value='amount', 
      unit='product', # add a unit 
      condition='product', 
      ax=ax) 
def myFormatter(x, pos): 
    return pd.to_datetime(x) 

# assign locator and formatter for the xaxis ticks. 
ax.xaxis.set_major_formatter(mpl.ticker.FuncFormatter(myFormatter)) 

# put the labels at 45deg since they tend to be too long 
fig.autofmt_xdate() 
plt.show() 

Результат:

enter image description here

+0

Так что же здесь проблема ? У одного из временных рядов было только одно измерение? Я столкнулся с аналогичной проблемой, и я уверен, что все мои серии имеют более одного измерения. –

Смежные вопросы