22.6. Mixed-Up Code Questions

Create code to plot a line graph for the average yearly temperatures in US from 2015 to 2020. The x-axis should include years [2015, 2016, 2017, 2018, 2019, 2020]. The average temperatures during these years were [54.4, 54.9, 54.6, 53.5, 52.7, 54.4] respectively.

Create code to plot a line graph for the average company sales per month from January to March. The x-axis should include months [Jan, Feb, Mar]. The average sales during these months were [5000, 7000, 8000] respectively measured in dollars. Make sure to add labels ‘Months’ and ‘Sales (in Dollars)’ for both x-axis and y-axis respectively. Add the title ‘Total Sales per Month’.

Create code to plot two line graphs and plot them side-by-side. The first line graph uses the data where x= [1, 2, 3, 4, 5] and y= [9.3, 4.4, 5.2, 6, 7]. The second line graph uses x= [5, 10, 15, 20] and y= [6.7, 8.2, 7.4, 8.6]. Set figsize = 10,5. Add x-axis labels ‘Number of Miles’, y-axis labels of ‘Running Speed (in MPH)’, and a title ‘Marathon Running Speed in MPH by Mile’.

Create code to plot a vertical bar chart showing the number of people who like each movie genre. The x-axis is each movie genre including [‘Comedy’, ‘Action’, ‘Romance’, ‘Drama’, ‘SciFi’] with number of people who like each respective genre as [4.4, 5.9, 6.2, 1.7, 4.5] in thousands. Plot this as a singular subplot. Add x and y axes titles – ‘Movie Genre’ and ‘Number of People (in thousands)’ respectively – and the title ‘Movie Genre Preferences’.

Create code to plot two horizontal bar charts and plot them side-by-side. The first bar chart uses the data with x values of [9.3, 8.8, 7.9] and y values of [1, 2, 3]. The second horizontal bar chart has uses data with x values of [9.6, 6.8, 6.9, 6.2] and y values of [5, 10, 15, 20]. Set figsize = 10,5. Set axis labels for each graph so that the x-axis reads ‘Number of Mistakes’ and the y-axis reads ‘Hours of Practice’. Finally, add the title ‘Average Number of Mistakes in Code After Hours of Practice’.

Create code to plot a line graph with x values of [0, 10, 20, 30] and y values [105, 89, 70, 113]. Change the color of the line to red, set line width equal to 5, and add gridlines.

Create code to plot a pie chart that shows the popularity distribution for different genres of films. First specify the labels for the pie chart to be ‘Action’, ‘Adventure’, ‘Thriller’, ‘Drama’, ‘Romance’, ‘Comedy’, followed by their respective sizes [182, 164, 93, 22, 143, 88] and colors [‘red’, ‘green’, ‘gray’, ‘blue’, ‘pink’, ‘yellow’]. Add the title ‘Popularity Distribution of Movie Genres’.

Create code to plot a line graph with two lines. The x values should reflect years [‘2020’, ‘2021’, ‘2022’] and y values should reflect the average student GPA. ‘ABC College’ should have y values of [3.42, 3.37, 3.44] and a green line color while ‘XYZ University’ has y values of [3.23, 3.57, 3.61] and a blue line color. Both lines have square markers represented by ‘s’. Set an x-label ‘Year’, y-label ‘Average Student GPA’, and title ‘Average Student GPA per Year’. Lastly, create a legend.

Create code to plot two vertical bar charts on the same plot. One bar will represent the annual cost incurred by a store and the other bar will represent the annual revenue earned by the store, from 2014 to 2018. The x-axis will be the ‘Year’ and the y-axis is the ‘Amount (in Dollars)’. The first bar chart should be red and represented as ‘Cost’ with y values of [13000, 16000, 18000, 21000, 17000]. The second bar chart should be yellow and represented by ‘Revenue’ with y values of [41000, 33000, 67000, 73000, 66000]. Set the xticklabels equal to the years [2014, 2015, 2016, 2017, 2018]. Set width to 0.5 and figsize of 10,5. Add a legend and set the x-axis to ‘Year’, y-axis to ‘Amount (in Dollars)’ and the title to ‘Total Cost and Revenue Generated from 2014 to 2018’. Finally, add a grid.

Create code to make a 2x2 subplot each with a different type of graph, all with the same values. To do this, create a figure with figsize of (10,5). The x-values are letters [‘X, ‘Y’, ‘Z’] and the y-values are numbers [35, 65, 70]. The top left graph should be a vertical bar chart. The top right graph should be a scatterplot with magenta colored points and star markers represented by an asterisk (*). The bottom left graph should be an indigo colored line graph with line width of 3. The bottom right graph should be a horizontal bar chart. Title the graph ‘Categorical Plotting’.

You have attempted of activities on this page