I have csv file containing some hierarchical data and I’d like to create a visualisation like this:
Anybody know how I can do this, preferably using matplotlib?
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
data = {
'Scope': ['Scope Insertion', 'Scope Positioning', 'No Action'],
'Instrument': ['Instrument Insertion', 'Instrument Positioning', 'No Action'],
'Site': ['Fluid Wash', 'Debris Wash', 'No Action'],
'Pressure': ['Inflate Pressure', 'Deflate Pressure', 'No Action']
}
df = pd.DataFrame(data)
palette = {
'Scope Insertion': '#4CAF50',
'Scope Positioning': '#AED581',
'No Action': '#EEEEEE',
'Instrument Insertion': '#1E88E5',
'Instrument Positioning': '#90CAF9',
'Fluid Wash': '#FFB74D',
'Debris Wash': '#8D6E63',
'Inflate Pressure': '#9E9E9E',
'Deflate Pressure': '#757575'
}
fig, ax = plt.subplots(figsize=(10, 2))
sns.heatmap(
df.applymap(palette.get).replace(palette),
annot=df,
fmt='',
cmap=palette,
cbar=False,
linewidths=.5,
ax=ax
)
ax.set_title('Setup')
ax.set_xlabel('Setup')
ax.set_ylabel('GT')
plt.show()
replace(palette)
?
$\endgroup$
applymap(palette.get)
already transforms each value to its corresponding color, the replace(palette)
ensures to transform again where necessary.
$\endgroup$
Commented
Jun 13 at 5:12
ValueError: could not convert string to float: '#4CAF50'
$\endgroup$