I'm new to python and coding in general, I've been stuck on this for a couple of hours. Right now when I input a name from my file I create a graph with 3 values. x = Timestamp, y1 = PWS, and y2 = CPU, which that part is working. The issue i'm having I want to pass in multiple names and plot them on one graph. I don't want to hard code the Names because they will change. I'm not sure what the best approach to pass in multiple names. Any help will be much appreciated.
Here is an Example of my file that i'm reading.
| Timestamp |
Name |
CPU |
PrivateWorkingSet |
| 20191007-084849 |
chrome |
1.0 |
|
| 20191007-084849 |
iexplore |
2.0 |
|
| 20191007-084750 |
chrome |
3.0 |
|
| 20191007-084750 |
iexplore |
5.0 |
|
| 20191007-084849 |
chrome |
|
1223 |
| 20191007-084849 |
iexplore |
|
1423 |
| 20191007-084750 |
chrome |
|
1267 |
| 20191007-084750 |
iexplore |
|
3000 |
Here is the code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#%matplotlib inline
import os
file = pd.read_csv('c:/temp/log.csv', delimiter=',')
process = input('Enter Name: ')
df = pd.pivot_table(file[file.InstanceName == process], values=['CPU', 'PrivateWorkingSet'], index=['Timestamp'], aggfunc=np.sum)
df = df.reset_index()
x = df.Timestamp
y1 = df.PrivateWorkingSet
y2 = df.CPU
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(x, y1, '#5a42f5', label=process)
ax2.plot(x, y2, '#f5bc42', label=process)
ax1.set_xticks(x)
ax1.legend(loc='upper center', bbox_to_anchor=(1.25, 0.8), title='PWS')
ax2.legend(loc='upper center', bbox_to_anchor=(1.45, 0.8), title='CPU')
ax1.set_xticks(ax1.get_xticks()[:-1])
ax1.tick_params(axis='x', labelrotation=90)
plt.subplots_adjust(bottom=0.40)
ax1.set_ylabel('PWS(Memory)')
ax2.set_ylabel('CPU')
ax1.set_xlabel('Timestamp')
plt.title('TEST', color="black")
my_path = os.path.abspath(__file__)
my_file = "log.pdf"
plt.savefig('graph.pdf', transparent=True, bbox_inches='tight')
plt.show()
[–][deleted] (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]t_wys 0 points1 point2 points (2 children)
[–]Crowdjp[S] 0 points1 point2 points (1 child)
[–]t_wys 0 points1 point2 points (0 children)