0
votes

I am trying to graph 4 boxplots into one graph in Pandas. Using the codes below:

# Generate a box plot of the final tumor volume of each mouse across four regimens of interest
fig, ax = plt.subplots()
ax.boxplot(tumor_volume_at_final_time_point_dict.values())
ax.set_xticklabels(tumor_volume_at_final_time_point_dict.keys())
ax.set_ylabel("Tumor Volume at the Final Timepoint")
plt.show()

However the boxplots are not showing up in the output.

https://i.stack.imgur.com/NEtwS.png

Here are the codes of how I fill the dictionary with data.

# Put treatments into a list for for loop (and later for plot labels)
tumor_volume_at_final_time_point_dict = {"Capomulin":[],"Ramicane":[],"Infubinol":[],"Ceftamin":[]}


# Appending data to lists per key item in dictionary to fill with tumor vol data (for plotting)
capomulin_data = merge_mouse_clean_last_timepoint_df.loc[merge_mouse_clean_last_timepoint_df["Drug Regimen"] == "Capomulin"]
tumor_volume_at_final_time_point_dict["Capomulin"] = capomulin_data["Tumor Volume (mm3)"].tolist()

ramicane_data = merge_mouse_clean_last_timepoint_df.loc[merge_mouse_clean_last_timepoint_df["Drug Regimen"] == "Ramicane"]
tumor_volume_at_final_time_point_dict["Ramicane"] = ramicane_data["Tumor Volume (mm3)"].tolist()

infubinol_data = merge_mouse_clean_last_timepoint_df.loc[merge_mouse_clean_last_timepoint_df["Drug Regimen"] == "Infubinol"]
tumor_volume_at_final_time_point_dict["Infubinol"] = infubinol_data["Tumor Volume (mm3)"].tolist()

ceftamin_data = merge_mouse_clean_last_timepoint_df.loc[merge_mouse_clean_last_timepoint_df["Drug Regimen"] == "Ceftamin"]
tumor_volume_at_final_time_point_dict["Ceftamin"] = ceftamin_data["Tumor Volume (mm3)"].tolist()
 

Here is the dictionary data

tumor_volume_at_final_time_point_dict  =  {'Capomulin': [38.98287774, 38.93963263, 30.48598484, 37.07402422, 40.1592203, 47.68596303, 37.31184577, 38.1251644, 38.75326548, 41.48300765, 38.84687569, 28.43096411, 33.32909778, 46.53920617, 32.37735684, 41.58152074, 23.34359787, 40.72857787, 34.45529799, 31.02392294, 40.65812366, 39.95234669, 36.04104736, 28.48403281, 31.8962384], 'Ramicane': [38.4076183, 43.0475426, 38.81036633, 32.97852192, 38.34200823, 33.39765251, 37.31123552, 40.65900627, 29.12847181, 33.56240217, 36.37451039, 31.56046955, 36.13485243, 22.05012627, 30.56462509, 31.09533505, 45.22086888, 36.56165229, 37.22565033, 43.41938077, 30.27623175, 40.66771292, 43.16637266, 44.18345092, 30.63869575], 'Infubinol': [67.97341878, 65.52574285, 57.03186187, 66.08306589, 72.2267309, 36.3213458, 60.96971133, 62.43540402, 60.91876652, 67.28962147, 66.19691151, 62.11727887, 47.01036401, 60.16518046, 55.62942846, 45.69933088, 54.65654872, 55.65068132, 46.25011212, 54.04860769, 51.54243058, 50.00513807, 58.26844248, 67.68556862, 62.75445141], 'Ceftamin': [62.99935619, 45.0, 56.05774909, 55.74282869, 48.72207785, 47.7846818, 61.84902336, 68.92318457, 67.74866174, 57.91838132, 46.78453491, 59.85195552, 64.29983003, 59.74190064, 61.43389223, 64.19234114, 45.0, 52.92534846, 45.0, 67.52748237, 45.0, 64.63494887, 61.38666032, 68.59474498, 64.72983655]}

Can someone help me figure why the boxplots are not showing up properly?

Your issue is not reproducible: example and don't post data in your question as an image. - Trenton McKinney
@TrentonMcKinney Ah my apologies. I edited my post to include my dictionary data now - Itsnhantransitive
Using your data, the issue is still not reproducible: plot - Trenton McKinney
Maybe update matplotlib. I tested in 3.5.1 - Trenton McKinney
so it turned out all I had to do is restart and clear output and it gave me the right graph with all the boxplots.... @TrentonMcKinney - Itsnhantransitive