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.

Heatmap only supports equal row and column

See original GitHub issue

Description

heatmap only works for equal row and column.

Steps to reproduce

import proplot as plot
import pandas as pd

data = pd.DataFrame(index=list('abcdefghij'), columns=list('lmn'))
data = data.fillna(0)
print(data.values.shape)

# Covariance matrix plot
f, ax = plot.subplots(axwidth=4.5)
m = ax.heatmap(
    data, cmap='ColdHot', vmin=-1, vmax=1, N=100,
    lw=0.5, edgecolor='k', labels=True, labels_kw={'weight': 'bold'},
    clip_on=False, # turn off clipping so box edges are not cut in half
)
ax.format(
    suptitle='Heatmap demo', title='Table of correlation coefficients', alpha=0, linewidth=0,
    xloc='top', yloc='right', yreverse=True, ticklabelweight='bold',
    ytickmajorpad=4,  # the ytick.major.pad rc setting; adds extra space
)

Expected behavior (generated by seaborn):

import seaborn as sns
import pandas as pd

data = pd.DataFrame(index=list('abcdefghij'), columns=list('lmn'))
data = data.fillna(0)
sns.set()
ax = sns.heatmap(data, cmap="YlGn")

image

Actual behavior:

  File "E:\miniconda3\envs\satpy\lib\site-packages\proplot\subplots.py", line 217, in _iterator
    ret.append(func(*args, **kwargs))
  File "E:\miniconda3\envs\satpy\lib\site-packages\proplot\axes.py", line 1275, in heatmap
    obj = self.pcolormesh(*args, **kwargs)
  File "E:\miniconda3\envs\satpy\lib\site-packages\proplot\wrappers.py", line 3083, in _wrapper
    return driver(self, func, *args, **kwargs)
  File "E:\miniconda3\envs\satpy\lib\site-packages\proplot\wrappers.py", line 551, in standardize_2d
    f'Input shapes x {x.shape} and y {y.shape} must match '
ValueError: Input shapes x (10,) and y (3,) must match Z centers (10, 3) or Z borders (11, 4).

Proplot version

0.5.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
bradyrxcommented, Mar 31, 2020

I think ax.heatmap just doesn’t take raw pandas dataframes. If you do data.values it works.

Here’s an example with some random data inside and calling data.columns and data.index for proper labeling:

import proplot as plot
import pandas as pd


data = pd.DataFrame(index=list('abcdefghij'), columns=list('lmn'))
data[:] = np.random.rand(10, 3)

f, ax = plot.subplots(axwidth=4.5)
m = ax.heatmap(data.columns, data.index,
    data, cmap='ColdHot', vmin=-1, vmax=1, N=100,
    lw=0.5, edgecolor='k', labels=True, labels_kw={'weight': 'bold'},
    clip_on=False, # turn off clipping so box edges are not cut in half
)
ax.format(
    suptitle='Heatmap demo', title='Table of correlation coefficients', alpha=0, linewidth=0,
    xloc='top', yloc='right', yreverse=True, ticklabelweight='bold',
    ytickmajorpad=4,  # the ytick.major.pad rc setting; adds extra space
)

heatmap

1reaction
lukelbdcommented, May 10, 2020

This is fixed by #159. Note you can also make the grid boxes square by passing aspect='equal' to format() (which calls Axes.set_aspect()) although #159 also makes “equal” aspect ratio the default behavior for heatmaps, just like it is the default for imshow plots.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Heatmap only supports equal row and column #136 - GitHub
Description heatmap only works for equal row and column. Steps to reproduce import proplot as plot import pandas as pd data = pd....
Read more >
A Complete Guide to Heatmaps | Tutorial by Chartio
Each cell in the heatmap is associated with one row in the data table. The first two columns specify the 'coordinates' of the...
Read more >
Chapter 2 A Single Heatmap | ComplexHeatmap Complete ...
One major advantage of ComplexHeatmap package is that it supports splitting the heatmap by rows and columns to better group the features and ......
Read more >
All About Heatmaps - Towards Data Science
Heatmaps are a compelling way to visualize relationships between variables in high dimensional space. It can be done using feature variables as ...
Read more >
sheatmap: Plot a heatmap with values as close to the diagonal ...
Whether to apply the same order to both rows and columns (if reordering ... D2 instead of complete , since the only methods...
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