Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

a function to create multiple plots

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading