This is because of the type used, I just had this problem and solved it by specifying a dtype for my dataframe. In your similarities.info() seaborn wants to see DType:'float64' or another number type.

similarities = pd.DataFrame(..., dtype="float")

Answer from thesylio on Stack Overflow
🌐
Blogger
theprogrammersfirst.blogspot.com › 2021 › 07 › seaborn-heatmap-error-attributeerror.html
Theprogrammersfirst: Seaborn Heatmap Error: " AttributeError: 'NoneType' object has no attribute 'reshape' "
July 9, 2021 - I would like to create a Seaborn heatmap to visualize the correlations indicated in the DataFrame. But when I run the following code: sns.heatmap(similarities) I get a long error message that concludes with : AttributeError: 'NoneType' object has no attribute 'reshape' Can anyone help me figure out how to visualize this?
Discussions

Heatmap fails with Matplotlib pgf backend
Due to matplotlib/matplotlib#18407, uses of seaborn.heatmap errors out with AttributeError: 'NoneType' object has no attribute 'write' when using the pgf backend for Matplotlib. Min... More on github.com
🌐 github.com
2
November 9, 2020
python - Seaborn Heatmap correlation won't fit annotation digits - Stack Overflow
I'm trying to plot a triangular correlation matrix using seaborn heatmap but the cells won't fit the annotation digits. Any idea how I make them fit nicely inside their respective heatmap cell? I a... More on stackoverflow.com
🌐 stackoverflow.com
python - AttributeError: 'NoneType' object has no attribute 'reshape' - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
python - Error while drawing animation of seaborn heatmap for 3D volume - Stack Overflow
Trying to visualize the cross-correlation between two volumes, img_3D, and mask_3D, using Seaborn heatmap, and animation from Matplotlib to visualize the 3D cross-correlation result as a progressive More on stackoverflow.com
🌐 stackoverflow.com
June 16, 2020
🌐
DevCodevi
devcodevi.com › home › questions › seaborn heatmap error: “ attributeerror: ‘nonetype’ object has no attribute ‘reshape’ ”
Seaborn Heatmap Error: “ AttributeError: 'NoneType' object has no attribute 'reshape' ” - DevCodevi
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /var/folders/tb/j430qmhn16s6nsz08nf0y7y40000gn/T/ipykernel_40566/1345125298.py in <module> ----> 1 ax2 = sns.heatmap( 2 similarities, 3 vmin=-1, vmax=1, center=0, 4 cmap=sns.diverging_palette(20, 220, n=200), 5 square=True /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs) 44 ) 45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)}) ---> 46 return f(**kwargs) 47 return inner_f 48 /Library
🌐
Johnnn
johnnn.tech › home › questions › seaborn heatmap error: ” attributeerror: ‘nonetype’ object has no attribute ‘reshape’ “
Seaborn Heatmap Error: " AttributeError: 'NoneType' object has no attribute 'reshape' " - Johnnn
July 8, 2021 - TypeError Traceback (most recent call last) /var/folders/tb/j430qmhn16s6nsz08nf0y7y40000gn/T/ipykernel_40566/1345125298.py in <module> ----> 1 ax2 = sns.heatmap( 2 similarities, 3 vmin=-1, vmax=1, center=0, 4 cmap=sns.diverging_palette(20, 220, n=200), 5 square=True /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs) 44 ) 45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)}) ---> 46 return f(**kwargs) 47 return inner_f 48 /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seabor
🌐
Qandeel Academy
qandeelacademy.com › questions › seaborn-heatmap-error-attributeerror-nonetype-object-has-no-attribute-reshape
Seaborn Heatmap Error: " AttributeError: 'NoneType' object has no attribute 'reshape' "
July 7, 2021 - Seaborn Heatmap Error: " AttributeError: 'NoneType' object has no attribute 'reshape' " python matplotlib heatmap correlation seaborn ·
🌐
GitHub
github.com › mwaskom › seaborn › issues › 2343
Heatmap fails with Matplotlib pgf backend · Issue #2343 · mwaskom/seaborn
November 9, 2020 - Due to matplotlib/matplotlib#18407, uses of seaborn.heatmap errors out with AttributeError: 'NoneType' object has no attribute 'write' when using the pgf backend for Matplotlib. Minimal reproducible example import matplotlib import seabo...
Author   tlaundal
🌐
CopyProgramming
copyprogramming.com › howto › list-object-has-no-attribute-reshape
Python: Reshaping Not Possible: AttributeError on 'List' Object
May 17, 2023 - ----> 1 ax2 = sns.heatmap( 2 similarities, 3 vmin=-1, vmax=1, center=0, 4 cmap=sns.diverging_palette(20, 220, n=200), 5 square=True /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs) 44 ) 45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)}) ---> 46 return f(**kwargs) 47 return inner_f 48 /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seaborn/matrix.py in heatmap(data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, linewidths, linecolor, cbar, cbar_kws, cbar_ax, s
Top answer
1 of 2
2

As pointed in the comments, using square=False with figsize=(30, 15) fixed the problem.

2 of 2
-2

The issue is that your labels are taking too much space of your jupyter max width. You probably have 2 options, the first one is editing jupyter width according to this answer:

https://stackoverflow.com/a/34058270/2970272

The second one would be lowering how much you're using the plot space, by trimming your labels, lowering the font, removing the colorbar and such. From the code bellow check all the "## HERE" comments to easily find what I've changed.

import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Generate a dummy df
df = pd.DataFrame(np.random.rand(44,44))

label_lens = [16, 16, 16, 16, 16, 16, 16, 16, 20, 11,
              9, 10, 10, 16, 16, 16, 16, 12, 45, 10, 10,
             10, 10, 10, 10, 10, 10, 12, 12, 50, 50, 50,
             50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]
#label_lens= [5]*len(label_lens)

col_labels = []
for label_len in label_lens:
    col_labels.append(f"{'X'*label_len}"[:10]) ## HERE -- max char limit

df.columns = col_labels

# Build correlation matrix df
correlation_matrix = df.corr()

# Get Diagonal Mask. Square matrix is not relevant.
mask = np.triu(np.ones_like(correlation_matrix, dtype=bool))

# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(30, 20)) ## here increased figsize

## HERE - max tick font size
ax.tick_params(axis='both', labelsize=8)

# Draw the heatmap with the mask and correct aspect ratio
sns_plot = sns.heatmap(correlation_matrix,
                       mask=mask,
                       annot=True,
                       fmt='.2f',
                       square=True,
                       cbar=False) ## HERE removed colorbar
f.set_tight_layout(True)
## HERE - rotating ticks to give more space
plt.setp(ax.yaxis.get_majorticklabels(), rotation=-45)
plt.setp(ax.xaxis.get_majorticklabels(), rotation=-45)
plt.show()
#f.savefig("my_corr_matrix.pdf")
Find elsewhere
Top answer
1 of 1
3

Check this code:

import numpy as np
np.random.seed(0)
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from scipy.signal import correlate
import seaborn as sns
sns.set()

img = np.load('img.npy')
act = np.load('act.npy')

result = correlate(img, act, mode = 'same')

def updatefig(sl):
    ax.cla()
    print(sl + 1, ' / ', result.shape[2])
    sns.heatmap(result[..., sl], cbar = False)
    ax.set_title("frame {}".format(sl + 1))
    ax.axis('off')

fig, ax = plt.subplots()
ani = FuncAnimation(fig, updatefig, frames = result.shape[2], interval = 5)

plt.show()

which gives me this animation (I halved the animation reported below to reduce the file size under 2 MB, the code above reproduce all 40 frames):


EDIT

In order to add a fixed colorbar to the heatmap, check this code:

import numpy as np
np.random.seed(0)
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from scipy.signal import correlate
import seaborn as sns
sns.set()

img = np.load('img.npy')
act = np.load('act.npy')

result = correlate(img, act, mode = 'same')

def updatefig(sl):
    ax.cla()
    print(sl + 1, ' / ', result.shape[2])
    sns.heatmap(result[..., sl],
                ax = ax,
                cbar = True,
                cbar_ax = cbar_ax,
                vmin = result.min(),
                vmax = result.max())
    ax.set_title("frame {}".format(sl + 1))
    ax.axis('off')

grid_kws = {'width_ratios': (0.9, 0.05), 'wspace': 0.2}
fig, (ax, cbar_ax) = plt.subplots(1, 2, gridspec_kw = grid_kws, figsize = (10, 8))
ani = FuncAnimation(fig, updatefig, frames = result.shape[2], interval = 5)

plt.show()

which produces this animation (cut as the previous one):

🌐
Stack Overflow
stackoverflow.com › questions › 63866000 › attributeerror-module-seaborn-has-no-attribute-heatmap
python - AttributeError: module 'seaborn' has no attribute 'heatmap' - Stack Overflow
I am fairly new to Python. I am trying to run the below code and getting Module not found error. I tried checking seaborn version and it was the latest. After multiple tries I placed my file in a different path and it started working fine.
🌐
GitHub
github.com › mwaskom › seaborn › issues › 395
Heatmap example broken · Issue #395 · mwaskom/seaborn
December 10, 2014 - sns.set() flights_long = sns.load_dataset("flights") flights = flights_long.pivot("month", "year", "passengers") flights = flights.reindex(flights_long.iloc[:12].month) sns.heatmap(flights, annot=True, fmt="d") --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-16-a4971f1cd61c> in <module>() 6 flights = flights.reindex(flights_long.iloc[:12].month) 7 ----> 8 sns.heatmap(flights, annot=True, fmt="d") AttributeError: 'module' object has no attribute 'heatmap'
🌐
Seaborn
seaborn.pydata.org › generated › seaborn.heatmap.html
seaborn.heatmap — seaborn 0.13.2 documentation - PyData |
seaborn.heatmap(data, *, vmin=None, vmax=None, cmap=None, center=None, robust=False, annot=None, fmt='.2g', annot_kws=None, linewidths=0, linecolor='white', cbar=True, cbar_kws=None, cbar_ax=None, square=False, xticklabels='auto', yticklabels='auto', mask=None, ax=None, **kwargs)#
🌐
Kaggle
kaggle.com › questions-and-answers › 202740
AttributeError: module 'seaborn' has no attribute 'histplot'
Checking your browser before accessing www.kaggle.com · Click here if you are not automatically redirected after 5 seconds
🌐
Stack Overflow
stackoverflow.com › questions › 73391194 › getting-attributeerror-nonetype-object-has-no-attribute-canvas-when-calli
python - Getting "AttributeError: 'NoneType' object has no attribute 'canvas'" when calling seaborn.heatmap() - Stack Overflow
I'm trying to run some Python code on a Jupyter Notebook, but when I call the seaborn.heatmap() method to plot a confusion matrix I get the AttributeError. Here's the code throwing the error: ax = ...
🌐
freeCodeCamp
forum.freecodecamp.org › python
Three numerical errors in heatmap - Python - The freeCodeCamp Forum
February 11, 2022 - Tell us what’s happening: Describe your issue in detail here. My solution for the medical data visualizer project has three numbers wrong in the heatmap and fails the test. The numbers are associated with weight/height…
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-nonetype-object-has-no-attribute-shape
AttributeError: 'NoneType' object has no attribute 'shape' | bobbyhadz
April 8, 2024 - The Python "AttributeError: 'NoneType' object has no attribute 'shape'" occurs when we access the shape attribute on a None value, e.g.
🌐
GitHub
github.com › hacksider › Deep-Live-Cam › issues › 577
AttributeError: 'NoneType' object has no attribute 'reshape' · Issue #577 · hacksider/Deep-Live-Cam
September 13, 2024 - Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}} inswapper-shape: [1, 3, 128, 128] Exception in Tkinter callback Traceback (most recent call last): File "D:\anaconda3\envs\nev1-deep_live_cam_python310\lib\tkinter_init_.py", line 1921, in call return self.func(*args) File "D:\anaconda3\envs\nev1-deep_live_cam_python310\lib\site-packages\customtkinter\windows\widgets\ctk_button.py", line 554, in _clicked self._command() File "D:\pythoncode\CV\deepfakes\Deep-Live-Cam\new_model\modules\ui.py", line 132, in start_button = ctk.CTkButton(root, text='Start', curs
Author   mrbingo1024
🌐
Indian AI Production
indianaiproduction.com › home › blog › seaborn heatmap using sns.heatmap() | python seaborn tutorial
Seaborn Heatmap using sns.heatmap() | Python Seaborn Tutorial
September 8, 2019 - import seaborn as sns # for data visualization import pandas as pd # for data analysis import numpy as np # for numeric calculation import matplotlib.pyplot as plt # for data visualization ... To create a heatmap using python sns library, data is the required parameter. Creating a numpy array using np.linespace() function from range 1 to 5 with equal space and generate 12 values. Then reshape in 4 x 3 2D array format using np.reshape() function and store in array_2d variable.
🌐
Reddit
reddit.com › r/stablediffusion › attributeerror: 'nonetype' object has no attribute 'shape'
r/StableDiffusion on Reddit: AttributeError: 'NoneType' object has no attribute 'shape'
October 18, 2023 -

I used the ControlNet extension & the Realistic Vision checkpoint, and it keeps giving me this error, "AttributeError: 'NoneType' object has no attribute 'shape'" whenever I try to generate a image. Even not using them, I still get this error.

What is the issue and how can I fix it?

Edit: it turns out when trying to use ControlNet, I was matching one of the preprocessors with the wrong models.