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

String Literals and Plotting with Matplotlib

I’d like to plot an amplitude spectral density for a device with matplotlib. Typical units for these kinds of plots are sensor_units/Hz^(1/2). Because I have a few different kinds of sensors, I’d like to pass the correct sensor_units as each time I plot, so I’ve written the axis label as

r'Coupling {}$/\sqrt{\mathrm{Hz}}$'.format(units)

this gives the error

ValueError: unexpected '{' in field name

What do I need to change to get this working?

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 :

Double each { and } that should be interpreted literally.

r'Coupling {}$/\sqrt{{\mathrm{{Hz}}}}$'.format(units)
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