-1

I am Building a GUI by Python and want to plot the the daily bonus of employees depends on the user plotting target:

Bob=[100,30,50,90]
Sammy=[10,60,90,200] 
Tom=[70,90,90,90]

# input from GUI User is Tom
ploting_target='Tom'

if ploting_target=='Tom':`
   plt.plot([0,1,2,3], Tom)

elif ploting_target=='Sammy':
   plt.plot([0,1,2,3], Sammy)

plt.plot([0,1,2,3], Tom)

____________________________________________
#expecting  
#find_target=list_of_employee.index(ploting_target)

#plt(plot([0,1,2,3], list_of_employee[find_target])
3
  • 1
    What is your specific coding question? You might want to organize your data as a dictionary e.g.: plotting_dict = dict(Bob=[100,30,50,90], Sammy=[10,60,90,200],Tom=[70,90,90,90]) and plt.plot([0,1,2,3], plotting_dict[ploting_target]) Commented Oct 30, 2023 at 7:56
  • thanks for you comment, i want just to plot the daily bounce that the user want to plot, for example: the input is to Tom ( the bounce is saved as a list in python worksapce) Tom=[70,90,90,90]. so, what i need to write a code to plot these values that is all. Commented Oct 30, 2023 at 13:39
  • As per one of the duplicates, the simplest answer, w/o resorting to pandas, is plt.plot(Bob, 'g', Sammy, 'r', Tom, 'b'). And the other duplicate has the pandas approach: pd.DataFrame([Bob, Sammy, Tom]).T.plot() Commented Nov 1, 2023 at 2:34

1 Answer 1

0

Your question is unclear. If you have a list of employees, you can probably use Pandas to organize your data (almost the same as @JohanC suggested with dict):

# pip install pandas
import pandas as pd
import matplotlib.pyplot as plt

Bob = [100, 30, 50, 90]
Sammy = [10, 60, 90, 200] 
Tom = [70, 90, 90, 90]

df = pd.DataFrame({'Bob': Bob, 'Sammy': Sammy, 'Tom': Tom})
df.index = 'Date ' + df.index.astype(str)

Output:

>>> df
       Bob  Sammy  Tom
Day 0  100     10   70
Day 1   30     60   90
Day 2   50     90   90
Day 3   90    200   90

Now you can do df.plot():

enter image description here

Or for a specific employee df['Sammy'].plot():

enter image description here

Or for a list of employees (but not all) df[['Bob', 'Tom']].plot():

enter image description here

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.