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

How to round to 1 floating point in matplotlib

I have the following code to plot the bar graph.

import pandas.util.testing as testing
from pandas import DataFrame as df
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
# import matplotlib.pyplot.bar_label as bar_label
import warnings
warnings.filterwarnings("ignore")
df = testing.makeTimeDataFrame(freq='MS')
ax = df.A.plot(kind='bar')
ax.bar_label(ax.containers[0]);

It produces this plot:

enter image description here

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

How can round it to 1 floating point. Using a format such as this "{:.1f}".format(45.34531). I am unsure of how to apply it. Without it, the plot is illegible.

>Solution :

Try this:

ax.bar_label(ax.containers[0], fmt='%.1f') 
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