To plot a line chart with varying x and y values, you can plot each line separately using the plot function in a loop. Here's an example code snippet that should work with your input data:
The resulting plot should have the x-axis labeled as "Year", the y-axis labeled as "Sales Amount", and a title of "Sales Trend". Each line should be identified in the legend by the corresponding employee ID.
I hope this helps!
import numpy as np import matplotlib.pyplot as plt Salesamount = [[28000.00,308000.00,582000.00,387000.00],[367000.00,3037000.00,4822000.00,2936000.00],[637000.00,3440000.00,4415000.00,3294000.00],[478000.00,1209000.00,478000.00,1209000.00]] CalendarYear = [2010,2011,2012,2013] Employee = [272,281,282,296] fig, ax = plt.subplots() for i in range(len(Employee)): ax.plot(CalendarYear, Salesamount[i], label=str(Employee[i])) ax.legend(title='Employee') ax.set_xlabel('Year') ax.set_ylabel('Sales Amount') ax.set_title('Sales Trend') plt.show()This code loops through each set of sales amount data for each employee and plots it using the plot function with the corresponding calendar year values. The label parameter is set to the employee ID for each line, and a legend is added to the plot to identify each line.
The resulting plot should have the x-axis labeled as "Year", the y-axis labeled as "Sales Amount", and a title of "Sales Trend". Each line should be identified in the legend by the corresponding employee ID.
I hope this helps!
buran write Apr-09-2023, 04:55 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.