drazenz / heatmaps Goto Github PK
View Code? Open in Web Editor NEWBetter heatmaps in Python
License: BSD 3-Clause "New" or "Revised" License
Better heatmaps in Python
License: BSD 3-Clause "New" or "Revised" License
Hi,
I can't seem to plot a corrplot
. Here's what I'm running:
>>> import pandas as pd
>>> from sklearn import datasets
>>> from heatmap import corrplot
>>> iris = datasets.load_iris()
>>> X = pd.DataFrame(data=iris.data, columns=iris.feature_names)
>>> y = pd.DataFrame(data=iris.target, columns=['target'])
>>> df = pd.concat([X, y], axis=1)
>>> corrplot(df.corr())
I get:
Traceback (most recent call last):
File "/Users/shaked.z/myenv/lib/python3.6/site-packages/numpy/core/function_base.py", line 117, in linspace
num = operator.index(num)
TypeError: 'float' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/shaked.z/myenv/lib/python3.6/site-packages/heatmap/heatmap.py", line 129, in corrplot
palette=sns.diverging_palette(20, 220, n=256),
File "/Users/shaked.z/myenv/lib/python3.6/site-packages/seaborn/palettes.py", line 694, in diverging_palette
neg = palfunc((h_neg, s, l), 128 - (sep / 2), reverse=True, input="husl")
File "/Users/shaked.z/myenv/lib/python3.6/site-packages/seaborn/palettes.py", line 591, in light_palette
return blend_palette(colors, n_colors, as_cmap)
File "/Users/shaked.z/myenv/lib/python3.6/site-packages/seaborn/palettes.py", line 727, in blend_palette
pal = _ColorPalette(pal(np.linspace(0, 1, n_colors)))
File "<__array_function__ internals>", line 6, in linspace
File "/Users/shaked.z/myenv/lib/python3.6/site-packages/numpy/core/function_base.py", line 121, in linspace
.format(type(num)))
TypeError: object of type <class 'float'> cannot be safely interpreted as an integer.
Installed heatmapz 0.0.4 using pip. Thanks!
import pandas as pd
from heatmap import corrplot
tdf = pd.DataFrame([[1, -1, 3], [0, 3, 5]], columns=pd.Series(['A', 'B', 'C'], name='COLUMNS'))
test_corr = tdf.corr()
print(test_corr)
test_corr.index.name = 'index'
corrplot(test_corr)
Actual:
KeyError: 'index'
problem is this hardcoding:
~\Anaconda3\envs\cs\lib\site-packages\heatmap\heatmap.py in corrplot(data, size_scale, marker)
122
123 def corrplot(data, size_scale=500, marker='s'):
--> 124 corr = pd.melt(data.reset_index(), id_vars='index').replace(np.nan, 0)
125 corr.columns = ['x', 'y', 'value']
126 heatmap(
Workaround:
do test_corr.index.name = 'index' before the corrplot call
def corrplot(data, size_scale=500, marker='s'):
corr = pd.melt(data.reset_index(), id_vars='index').replace(np.nan, 0)
corr.columns = ['x', 'y', 'value']
heatmap(
corr['x'], corr['y'],
color=corr['value'], color_range=[-1, 1],
palette=sns.diverging_palette(20, 220, n=256),
size=corr['value'].abs(), size_range=[0,1],
marker=marker,
x_order=data.columns,
y_order=data.columns[::-1],
size_scale=size_scale
)
This is the function which leads to error.
However, changing to x_order=data.index can fix the bug
I have downloaded the code and edited a bit so that the functions will return both the axes (the one where the scatterplot is drawn and the one where the sidebar is drawn) so that users can further customize these plots for more aesthetics.
Hey @dylan-profiler!
Thanks for this library, do you any idea on how to add the marker size to the legend/plot?
Thanks in advance!
Very useful implementation - Please add a license for the community!
This simple thing can allow to us to add our own customizations. The most immediate one for me being mask
. just add similar code from the heatmap function. also the dictionary.update function might allow me to add my own palette directly from kwargs too.
I am running your latest code in python 2.7.16.
I get a run time error
File "/Users/tom/Desktop/Labcyte/data/heatmap.py", line 110, in heatmap
linewidth=0
TypeError: barh() takes at least 3 arguments (4 given)
My call looks like this.
corr_df = df
print corr_df[col_numer].corr()
plt.figure(figsize=(7, 7))
corrplot(corr_df[col_numer].corr().replace(np.nan, 0), size_scale=500)
What's wrong?
Your code just defines functions, has no main part.
Can you provide examples for how to actually use your code to produce graphics?
This approach looks really great, thank you. I haven't managed to apply formatting for fonts etc. - is it possible? I tried using Matplotlib's RC parameters, but they have no effect. Is there a way to do it?
Hi,
Is it possible to add the actual correlation score to the heatmap, similar to seaborn's annotate?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.