Reputation: 3253
I need to add the following information
score_to_plot = pd.DataFrame({"a":["c1", "c2", "c3", "c4"],
"max_score":[69,77,87,99],
"min_score":[55, 72, 83, 94]})
as a "box plot", such that left side of a box starts at the min_score
and right_side of a box ends at the max_score
, to the plot below. Having the scores range to be as an additional axis at the top.
Note that here bottom and top ranges are about the same, but in my actual work it is not the case and I cannot use one axis range.
f, ax = plt.subplots()
sns.set_color_codes("pastel")
sns.barplot(x="time", y="a", data={"a":["c1", "c2", "c3", "c4"], "time":[50,70,85,150]},
label="time_total", color="b")
sns.set_color_codes("muted")
sns.barplot(x="time", y="a", data={"a":["c1", "c2", "c3", "c4"], "time":[20,40,65,135]},
label="time_productive", color="b")
ax.legend(ncol=2, loc="lower right", frameon=True)
ax.set(ylabel="",
xlabel="Productive time vs total time vs score")
sns.despine(left=True, bottom=True)
How would I do this? Thank you for help!
An approximate idea of what I want as a result
Upvotes: 1
Views: 432
Reputation: 5836
I have saved score_to_plot
as df
. With following addition:
df["widths"] = df["max_score"]-df["min_score"]
ax2 = ax.twiny()
ax2.barh(df.a, df.widths, left=df.min_score, color="grey")
plt.xlim([0,100])
ax.legend(loc='lower left')
Upvotes: 1