0

I have a dictionary of values (drug) as follows:

{0: {0: 100.0, 1: 0.41249706379061035, 2: 5.144449764434768, 3: 31.078456871927678}, 1: {0: 100.0, 1: 0.6688801420346955, 2: 77.32360971119694, 3: 78.15132480853421}, 2: {0: 100.0, 1: 136.01949766418852, 2: 163.4967732211563, 3: 146.7726208999281}}

It contains 3 drug types, then the efficacy of that drug type in 4 different concentrations.

I'm trying to make a clustered bar chart which compares the 3 drugs against each other like this:

enter image description here

Currently, my code is the following:

fig, ax = plt.subplots()
width = 0.35
ind = np.arange(3)

for x in range(3):
    ax.bar(ind + (width * x), drug[x].values(), width, bottom=0)

ax.set_title('Drug efficacy')
ax.set_xticks(ind + width / 2)
ax.set_xticklabels(list(string.ascii_uppercase[0:drugCount]))

ax.autoscale_view()

plt.show()

I have adapted the code from this guide, but am having multiple problems.

I think the main reason is that the data used in the example is such that values in one group correspond to the same colour rather than the same cluster.

How can I adapt this code such that it will plot the efficacy of each drug in the 4 different concentrations in isolation compared to the other drugs?

1
  • 1
    Try pd.DataFrame.from_dict(drug_dict, orient='index').plot.bar()? Commented Oct 12, 2020 at 18:36

1 Answer 1

1

IIUC you want to normalize your values by column, which can be done using sklearn:

from sklearn import preprocessing

df = pd.DataFrame(drug)
scaler = preprocessing.MinMaxScaler()
df = pd.DataFrame(scaler.fit_transform(df))
df.T.plot(kind="bar")
plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply, I'll give that a go - any idea why 0 does not show as 100 in this situation yet 2 does for drug 2?
Not sure If i get it correctly, but when you normalize the values to 0-1 the lowest value becomes 0. Thus in drug 2 the first one becomes 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.