I am new to Python programming. I want to plot KPI for data given below. I have plotted bar graph for my requirement. Now my next task is to plot the KPI on bar graph.
data = {'processA': 6.412217965,
'processB': 6.454000000,
'processC': 6.762073277,
'processD': 6.760742288,
'processE ': 0.000000000,
'processF': 0.000000000,
'processG': 6.485000000,
'processH': 8.564758300,
'processI': 10.154632568,
'processJ': 7.397341767,
'processK': 9.2329058,
'processL': 11.509859317,
'processM': 11.907475931,
'processN': 12.701401764,
'processO': 12.701411712}
I pasted my code for plotting horizontal bar graph.
plt.figure(figsize=(18, 8))
plt.barh(processes, time, left=time, align='edge')
plt.xlim(0, 15)
plt.xlabel('Time:s.ns')
plt.ylabel('processes')
plt.title('processes with respective time starts')
plt.yticks(rotation=45)
plt.show()
Now, I want to show any KPI(eg: average,mean) on my bar graph like below
CodePudding user response:
The problem here is that you did not define what is processes and time. You can use pandas to work around your data that will make your life easier.
import matplotlib.pyplot as plt
import pandas as pd
data = {
'processA': 6.412217965,
'processB': 6.454000000,
'processC': 6.762073277,
'processD': 6.760742288,
'processE': 0.000000000,
'processF': 0.000000000,
'processG': 6.485000000,
'processH': 8.564758300,
'processI': 10.154632568,
'processJ': 7.397341767,
'processK': 9.2329058,
'processL': 11.509859317,
'processM': 11.907475931,
'processN': 12.701401764,
'processO': 12.701411712
}
df = pd.Series(data, name='time').to_frame()
df.index.name = 'processes'
df.reset_index(inplace=True)
print(df.head())
plt.figure(figsize=(18,8))
plt.barh(df.processes, df.time, left=df.time, align='edge')
plt.xlim(0, 15)
plt.xlabel('Time:s.ns')
plt.ylabel('processes')
plt.title('processes with respective time starts')
plt.yticks(rotation=45)
plt.show()
BTW I still don't understand what's your objective here with the plot. You can just take it as a reference.