Closed Soudaaa closed 4 years ago
I just did the same research about converting to abbreviated units. As you might know, Pint module is part of the Metpy code as a dependency. This is the module that attach the units to the values and uses the long format by default. As such, I searched in the Pint documentation where it gives examples in converting from long format to abbreviated format for units.
There are 2 ways to do this with the print function depending on the Python version. You need to use a Pint print formatter to abbreviate the units. As an example:
Python 3.6+:
plt.figtext( 0.8, 0.54, f'{sbcape:~P}')
Older formatting method in Python:
plt.figtext( 0.8, 0.54, '{:~P}'.format(sbcape)) # removed J/kg in the string
I was debating if I was going to put the severity indexes inside or outside the Skew-T graphic. Because I display on a web page I decided to put it outside in a web table. I was looking for a way to abbreviate units which I did find. So it is not a bug after all.
N.B. Please be aware that this will convert to a string. It won't retain the Pint format.
I just did the same research about converting to abbreviated units. As you might know, Pint module is part of the Metpy code as a dependency. This is the module that attach the units to the values and uses the long format by default. As such, I searched in the Pint documentation where it gives examples in converting from long format to abbreviated format for units.
There are 2 ways to do this with the print function depending on the Python version. You need to use a Pint print formatter to abbreviate the units. As an example:
Python 3.6+: plt.figtext( 0.8, 0.54, f'{sbcape:~P}') Older formatting method in Python: plt.figtext( 0.8, 0.54, '{:~P}'.format(sbcape)) # removed J/kg in the string
I was debating if I was going to put the severity indexes inside or outside the Skew-T graphic. Because I display on a web page I decided to put it outside in a web table. I was looking for a way to abbreviate units which I did find. So it is not a bug after all.
N.B. Please be aware that this will convert to a string. It won't retain the Pint format.
Thanks for your answer.
Problem solved.
So, I'm trying to adaptate a SkewT example script to plot UWYO soundings with some severe weather parameters included, which is running fine.
The thing that is bothering me, is the fact that the parameters units are not abbreviated when plotting the sounding, which consumes a lot of space and ends up getting out of the bounds of the image.
Although not a major issue, I tried to fix this with no success and I'm not sure if this somekind of bug or I'm not seeing what I'm doing wrong (probably the latter), so I've included the code and the output.