question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Seaborn doesn't support PeriodIndex

See original GitHub issue

Seaborn doesn’t properly support pandas PeriodIndex: dates should be converted to their actual values before being plotted.

import pandas as pd #Pandas 0.18.1
import seaborn as sns #Seaborn 0.7.0
index = pd.PeriodIndex(start='2000', end='2005', freq='A')
df = pd.DataFrame(np.random.randint(0,10,(len(index), 2)), index=index, columns=['A', 'B'])
sns.heatmap(df)

download

I’m not familiar with PRs, I guess there’s not much to change as converting the PeriodIndex to a regular datetime type does the trick sns.heatmap(df.pipe(lambda x: x.set_index(x.index.to_datetime())))

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
davidgilbertsoncommented, Jun 22, 2022

pandas: 1.4.2 matplotlib: 3.5.2 Python: 3.10.2

BTW Seaborn is great. Good docs too, things are nicely explained.

0reactions
mwaskomcommented, Jun 22, 2022

Weird, what version of pandas / matplotlib are you on?

Agreed that this is really something that should be made to work better in pandas.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making `matplotlib.pyplot.plot()` work with `PeriodIndex
OrderQuantity.plot() is not an option because I am trying to have multiple dataframes on the same graph (test and training data), and some ......
Read more >
Frequently asked questions — seaborn 0.12.1 documentation
Because seaborn is pure Python, it won't directly encounter these problems, but its dependencies (numpy, scipy, matplotlib, and pandas) might.
Read more >
Working with Time Series | Python Data Science Handbook
This encodes a fixed-frequency interval based on numpy.datetime64 . The associated index structure is PeriodIndex . For time deltas or durations, Pandas ...
Read more >
Working with Time Series in Pandas - Medium
There may be strings in the index that do not represent a date. ... Period and PeriodIndex objects can be converted to another...
Read more >
Time Series Data Visualization with Python
Sometimes it can help to change the style of the line plot; for example, ... not all problems with data say having typical...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found