I am trying to reproduce the table of barplots (created below in tableau) in Python.
I am struggling to figure out how to do it python (matplotlib, seaborn, pandas).
Here is some example data that illustrates the problem:
import pandas as pd
import numpy as np
data = dict(
correlation=np.random.normal(0, 0.5, 100),
pvalue=np.random.normal(0.05, 0.02, 100),
variable=np.tile(np.array([f"variable{i}" for i in range(10)]), 10),
model=np.repeat(np.array([f"model{i}" for i in range(10)]), 10)
)
data = pd.DataFrame(data)
data["significant"] = data["pvalue"] < 0.05
data["positive"] = data["correlation"] > 0
My attempted plot for ONE MODEL ("model1") illustrates roughly what I am looking for. As I said I am trying to reproduce the table of barplots (shown above), which would display the results for all of the models.
example_plot_data = data.loc[data.model == "model1"]
example_plot_data.plot(
kind="bar", x="variable", y="correlation",
color=example_plot_data.positive.map({True: "b", False: "r"}),
rot=70,
)
plt.show()
Ideally these are the aesthetics I am looking for
# Aesthetics for the plots:
columns = data["model"]
rows = data["variable"]
bar_size = data["correlation"] # ideally centred on zero
bar_color = data["correlation"] # ideally centred on zero (RdBu)
bar_significance = data["significant"]



