I want to create a function in Python so that I just input the name of country and it will create all 4 plots. Basically, a function to replace 4 single codes as below:
plt.figure(1)
plotCT(viz1,'Czechia')
plt.figure(2)
plotCT(viz2,'Czechia')
plt.figure(3)
plotCT(viz3,'Czechia')
plt.figure(4)
plotCT(viz4,'Czechia')
Do you have any idea for that? Thank you.
>Solution :
You could define a function which accepts a list of your viz objects and a string country name, then iterates through the list with a for loop to plot each item:
def generate_figures(country_name, viz_list):
# Iterates through each viz in viz_list.
for index, viz in enumerate(viz_list):
# Plots the given viz element.
plt.figure(index)
plotCT(viz, country_name)
generate_figures("Czechia", [viz1, viz2, viz3, viz4])