String Literals and Plotting with Matplotlib
Question:
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?
Answers:
Double each {
and }
that should be interpreted literally.
r'Coupling {}$/sqrt{{mathrm{{Hz}}}}$'.format(units)
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?
Double each {
and }
that should be interpreted literally.
r'Coupling {}$/sqrt{{mathrm{{Hz}}}}$'.format(units)