Answered step by step
Verified Expert Solution
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 makebarchart below. The elements requested by the management team for the first visualization are:
Make plots, each of which is a bar chart representing the total visitation as yaxis of each state shown in xaxis in year and 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 eg A proper title of the plot using visitation data could be something like Visitation data
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 makebarchartdata:
df pdDataFramedata
dfsetindexstate inplaceTrue
#Define function for annotating lowest to highest:
def annotatedfaxdf:
maxvalue dfmax
minvalue dfmin
#identifying the max & min:
maxindex dfidmax
minindex dfidmin
# for loop to itterate through the dfeach year:
for index, value in data.items:
#set condition for max & min:
# identified max & min will have arrow pointed
# Make sure that arrow is placed above the bar
if value maxvalue:
axannotatefMax: maxvalue xy index value xytext index value
arrowpropsdictfacecolor'black', arrowstyle
horizontalalignment 'center', verticalalignment'bottom'
elif value minvalue:
axannotatefMin: minvalue xyindex value xytextindex value
arroepropsdictfacecolor'black', arrowstyle
horizontalalignment'center', verticalalignment'bottom'
#To plot each year's data:
fig, axs pltsubplots figsize
#Define years & colors:
visitationyears visitation 'visitation 'visitation 'visitation
colors lightgreen 'salmon', 'gold', 'skyblue'
#to set up itterate through the df:
for x year in enumeratevisitationyears:
row x
col x
ax axsrow col
axbardfindex, dfyear color colorsx
axsettitlefVisitation data year
annotatedfax dfyear
pltshow
#return
makebarchartloaddata
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started