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

List comprehension for matplotlib methods

ax[0].set_ylabel("Valor")
ax[1].set_ylabel("Máximos y Mínimos")
ax[2].set_ylabel("Fear and Greed")
ax[3].set_ylabel("Put Call Ratio")
ax[4].set_ylabel("T10Y2Y")
ax[5].set_ylabel("RASI")
ax[6].set_ylabel("Oscilador Mcclellan")

I’m trying to put all of these in a list comprehension, something like this but doesn’t work:

[[ax[i].set_ylabel(x) for i in range(7)] for x in ['Valor', 'Máximos y Mínimos', 'Fear & Greed', 'Put Call Ratio', 'T10Y2Y', 'RASI', 'Oscilador Mcclellan']]

Can’t get the number on ax[] with the exact string for each one. Any ideas?

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 :

This is a job for enumerate:

[ax[i].set_ylabel(x) for i, x in enumerate(['Valor', 'Máximos y Mínimos', 'Fear & Greed', 'Put Call Ratio', 'T10Y2Y', 'RASI', 'Oscilador Mcclellan'])]
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