Convert YAMLized pandas DataFrame to Seaborn clustermap
Project description
The aclustermap
package takes a YAMLized pandas DataFrame as input, with optional formatting keywords, and outputs a Seaborn clustermap .png image:
cat example.yaml | aclustermap > example.png
If YAMLizing a pandas DataFrame is a new concept, here is a quick tutorial.
Let's create a Python module generate_example.py
import pandas, yaml;
# Generate random data with make_blobs to yield interesting clustering behavior
from sklearn.datasets import make_blobs;
example = pandas.DataFrame(make_blobs(n_samples=36, centers=3, n_features=10)[0])
# Convert the DataFrame to a dict
df_dict = example.to_dict()
# Convert the dataframe to a dict, then YAMLize the dict
yml = yaml.dump(df_dict)
# Print to stdout
print(yml)
Here is a one-liner that combines the previous code to generate this dataframe, safe it to a file, and then output it as a clustermap to example.png:
python generate_example.py > example.yaml
cat example.yaml | aclustermap > example.png
Saving the dataframe to a file is not necessary, as it can be piped directly to aclustermap:
python generate_example.py | aclustermap > example.png
aclustermap
uses the simplest possible way to tweak the visualization, which is to pass a second YAML dict containing keyword argumnets for seaborn.clustermap and see also, seaborn.set_context, pyplot.setp with the Artist being the clustermap's xticklabels
or yticklabels
, or pyplot.rcParams.
The formatting must be enclosed in a dict labeled according to the function it applies to. Here is the default formatting, which will be used if no formatting is specified.
Otherwise, simply cat
a YAMLized nested dictionary with a structure similar to the following.
format:
seaborn:
clustermap:
cmap: CET_CBL1
annot: true
set_context:
context: notebook
pyplot:
setp:
xticklabels:
rotation: 0
yticklabels:
rotation: 0
rcParams:
font.size: 12
A convenient way to specify minor formatting tweaks directly at the command line is with a HereDoc:
(python generate_example.py; cat <<EOF) | python -m aclustermap > example.png
format:
seaborn:
clustermap:
annot: false
EOF
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aclustermap-0.1.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad42c8e42f36520f7c031670810c9e3a1316dd6a8b1b6770c61513c38eb3cd1a |
|
MD5 | e1d2794790e4540d28dffb58f6097998 |
|
BLAKE2b-256 | a4c59064d7ceb5c0d45d0f428334d0ee9dc75bfc52b41e74ded72aee3b6d965a |