Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi , basically I need some help in tweaking my work since I keep getting an error. To give some context, the question is as

Hi, basically I need some help in tweaking my work since I keep getting an error. To give some context, the question is as follows:
"Make use of the merged data to complete the function `make_bar_chart` below. The elements requested by the management team for the first visualization are:
* Make 4 plots, each of which is a bar chart representing the total visitation (as y-axis) of each state (shown in x-axis) in year 2016,2017,2018 and 2019. Each plot should use the data for each year.
* Make the figures readable by adjusting the figure size, and specify the year of each plot using the title (e.g., A proper title of the plot using 2016 visitation data could be something like Visitation data 2016.)
* For each plot, place two markers (style of your choice): one above the bar with the highest visitation and one above the bar with the lowest visitation."
def make_bar_chart(data):
df = pd.DataFrame(data)
df.set_index('state', inplace=True)
#Define function for annotating lowest to highest:
def annotate_df(ax,df):
max_value = df.max()
min_value = df.min()
#identifying the max & min:
max_index = df.idmax()
min_index = df.idmin()
# for loop to itterate through the df(each year):
for index, value in data.items():
#set condition for max & min:
#1) identified max & min will have arrow pointed
#2) Make sure that arrow is placed above the bar
if value == max_value:
ax.annotate(f'Max: {max_value}', xy =(index, value), xytext =(index, value+100),
arrowprops=dict(facecolor='black', arrowstyle='->'),
horizontalalignment ='center', verticalalignment='bottom')
elif value == min_value:
ax.annotate(f'Min: {min_value}', xy=(index, value), xytext=(index, value +100),
arroeprops=dict(facecolor='black', arrowstyle='->'),
horizontalalignment='center', verticalalignment='bottom')
#To plot each year's data:
fig, axs = plt.subplots(2,2, figsize=(12,10))
#Define years & colors:
visitation_years =['visitation_2016', 'visitation_2017', 'visitation_2018', 'visitation_2019']
colors =['lightgreen', 'salmon', 'gold', 'skyblue']
#to set up itterate through the df:
for x, year in enumerate(visitation_years):
row = x//2
col = x%2
ax = axs[row, col]
ax.bar(df.index, df[year], color = colors[x])
ax.set_title(f'Visitation data {year}')
annotate_df(ax, df[year])
plt.show()
#return
make_bar_chart(load_data())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago