Question

In: Computer Science

Graphs with Matplotlib Using the library Matplotlib and the provided data files create the following graphs:...

Graphs with Matplotlib Using the library Matplotlib and the provided data files create the following graphs:

I) Pie chart

Create a pie chart that shows the percentage of employees in each department within a company. The provided file: employee_count_by_department.txt contains the data required in order to generate this pie chart.

II) Line Graph

Create a line graph that shows a company's profit over the past ten years. The provided file: last_ten_year_net_profit.txt contains the data required in order to generate this line graph.

III) Bar Graph

Create a bar graph that shows a company's profit over the past ten years. The provided file: last_ten_year_net_profit.txt contains the data required in order to generate this bar graph. Info: Be sure to label all the axes of each graph with meaningful labels and provide an appropriate title to each of the graphs (mentioned above) being generated. Hint, the names of the files and the headers provided in each of the data files should help

-----------------------

last_ten_year_net_profit.txt

Year ; Profit in $USD

2009 ; $175,000

2010 ; $250,000

2011 ; $525,000

2012 ; $239,000

2013 ; $1,000,000

2014 ; $1,000,500

2015 ; $500,000

2016 ; $740,000

2017 ; $5,625,000

2018 ; $100,000,000

--------------------------

employee_count_by_department.txt

Department Name    , Total number of employees

Marketing       , 50

Information Technology, 275

Management      , 230

Human Resources    , 250

Finance        , 92

Supply Chain     , 73

Manufacturing     , 30

Solutions

Expert Solution

# matplotlib library
import matplotlib.pyplot as plt

# bar graph
def barGraph(x_values,y_values):
   bargraph = plt.figure(figsize=(6,4))
   plt.bar(x_values,y_values)
   plt.xlabel("year")
   plt.ylabel("profit")
   plt.title("yearly vise profits")
   plt.show()

# pie chart
def pieChart(x_values,y_values):
   piechart = plt.figure(figsize=(6,4))
   plt.pie(y_values, labels = x_values,autopct='%1.2f%%')
   plt.title("percentage of employees department vise")
   plt.show()

# line graph
def lineGraph(x_values,y_values):
   linegraph = plt.figure(figsize=(6,4))
   plt.plot(x_values,y_values)
   plt.xlabel("year")
   plt.ylabel("profit")
   plt.title("yearly vise profits")
   plt.show()

# main function
def main():
   x_values = []
   y_values = []

   # read input file
   with open("last_ten_year_net_profit.txt","r") as rdf:
       lines = rdf.readlines()
       # line by line
       for line in lines[1:]:
           # separate columns by ;
           tup = line.split(";")
           # type conversion
           x_values.append(int(tup[0]))
           value=0
           for i in tup[1]:
               try:
                   value=value*10+int(i)
               except:
                   continue
           y_values.append(value)
   # plot bar graph
   barGraph(x_values,y_values)

   # plot line graph
   lineGraph(x_values,y_values)

   x_values=[]
   y_values=[]
   # read input file
   with open("employee_count_by_department.txt","r") as rdf:
       lines = rdf.readlines()
       # line by line
       for line in lines[1:]:
           # separate columns by ,
           tup = line.split(",")
           # type conversion
           x_values.append(tup[0])
           y_values.append(int(tup[1]))
   # plot pie chart
   pieChart(x_values,y_values)

if __name__ == '__main__':
    main()


Related Solutions

1. Collect annual data to create data tables and graphs of the following: a. growth rates...
1. Collect annual data to create data tables and graphs of the following: a. growth rates of NGDP and RGDP for the years 2008-2018 b. CPI-All Urban Consumers (Current Series) and the inflation rate for the years 2008-2018 c. unemployment rate for the years 2008-2018 d. M1 and M2 for the years 2008-2018
The purpose of this is to plot data using Matplotlib. Description complete the Jupyter notebook named...
The purpose of this is to plot data using Matplotlib. Description complete the Jupyter notebook named main.ipynb that reads in the file diamonds.csv into a Pandas DataFrame. Information about the file can be found here: ------- diamonds R Documentation Prices of over 50,000 round cut diamonds Description A dataset containing the prices and other attributes of almost 54,000 diamonds. The variables are as follows: Usage diamonds Format A data frame with 53940 rows and 10 variables: price price in US...
Using Python and networkx library, choose two graphs (one with a small and the other large...
Using Python and networkx library, choose two graphs (one with a small and the other large sample size) from a data network library on the web, and read them using code. Write a script using python that reads the network data and plots the data in to a graph (using networkx).
When using random access files in Java, the programmer is permitted to create files which can...
When using random access files in Java, the programmer is permitted to create files which can be read from and written to random locations. Assume that a file called "integers.dat" contains the following values: 25 8 700 284 63 12 50 Fill in blanks: You are required to write the following Java code statements: (a) create a new stream called, blueray, which allows the program to read from and write to the file, "integers.dat." _____________________ (b) Write a statement which...
Please write code in c++ using iostream library. Also you can use any string library. Create...
Please write code in c++ using iostream library. Also you can use any string library. Create structure plane with the following: 1)plane's ID[int type] 2) location[char*] 3) departure time[char*] Your task is to find the plane with the smallest departure time for the selected city. Pointer, dynamic array and structures have to be used in this code. Input: NOTE: It's just an example of input, you should write code generally for any inputs. First line contains n(0 < n <...
Create a C# application for Library that allows you to enter data for books and saves...
Create a C# application for Library that allows you to enter data for books and saves the data to a file named Books.txt. Create a Book class that contains fields for title, author, number of pages, and price of the book and ToString() method. The fields of records in the file are separated with asterisk (*). Expecting sentinel value for ending the process of writing to file is "000"
I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data...
I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data from a CSV file, which has no names, just numbers. All I did was to read a .csv file. How do I pull data from three columns which contains about 1500 rows with just numbers and make a scatter plot with two in the x-axis and the third in the y-axis?
Draw the graphs of the NRZ-L, Manchester, and Pseudoternary schemes using the following data streams, assuming...
Draw the graphs of the NRZ-L, Manchester, and Pseudoternary schemes using the following data streams, assuming that the last signal level has been positive. (0110101101)
Create files with the following names : test1, test2, test3. Create a symbolic link to test2...
Create files with the following names : test1, test2, test3. Create a symbolic link to test2 and name it test4 Create a directory and name it test5. Write a shell script to perform the following tasks: • check if a file named test6 exist. If not, it should create it. • Display a text to indicate whether test4 is symbolic link or not • Display a text to indicate whether test2 is directory or not • Display a text to...
using java Define a class Library based on the following specifications: a. A library can have...
using java Define a class Library based on the following specifications: a. A library can have multiple books. Decide on the best possible data structure to store books. b. A library has a name. c. A library has an address. Define a 2-argument constructor for the Library class. Decide on the arguments needed for this constructor. e. Define a method that can add new books to the library. f. Define a method that allows a book to be borrowed (checked...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT