1

Hi i have a dataframe called metrics which has 2 rows × 31 columns.

I am plotting a graph using this:

unit_ids = sorting_rec.unit_ids
plt.figure(figsize=(12, 8))
sw.plot_unit_templates(we, unit_ids=unit_ids)
plt.suptitle(name, fontsize=12, y=0.01) 
plt.tight_layout(rect=[0, 0.05, 1, 1])
plt.savefig(name+"_xx.png", bbox_inches='tight')

My PI wants me to plot the related dataframe also side by side as a subplot so that it is easy to see the values and the graph both at the same time.

I tried some methods but the output is not something that I desire, the ouput looks like this : enter image description here

1 Answer 1

0

you must create the dataframe and a table to pass the data into it and display it beside the chart: First, create a dataframe for the table. In this code, I call it summary_df:

summary_df = pd.DataFrame({
'Mean': df.mean(),
'Sum': df.sum()}).T

Then, you must add the table:

table = plt.table(cellText=summary_df.values,
colWidths=[0.2]*len(summary_df.columns),
rowLabels=summary_df.index,
colLabels=summary_df.columns,
cellLoc='center',
rowLoc='center',
loc='bottom')

Finally, you must adjust the program layout to make space for the table. In this code, I prefer to show my table on these axes.

plt.subplots_adjust(left=0.2, bottom=0.2)
Sign up to request clarification or add additional context in comments.

Comments

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.