0

I want to change the font size of the label of my Bars. The below snippet isn't working...it's almost overlapping each other.

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd

sns.set_context('paper')
report_id = ['Report_1', 'Report_2', 'Report_3', 'Report_4', 'Report_5', 'Report_6', 'Report_7', 'Report_8', 'Report_9',
             'Report_10', 'Report_11', 'Report_12', 'Report_13', 'Report_14', 'Report_15', 'Report_16', 'Report_17',
             'Report_18', 'Report_19', 'Report_20', 'Report_21', 'Report_22', 'Report_23', 'Report_24', 'Report_25',
             'Report_26', 'Report_27', 'Report_28', 'Report_29', 'Report_30', 'Report_31', 'Report_32', 'Report_33',
             'Report_34', 'Report_35', 'Report_36', 'Report_37', 'Report_38', 'Report_39', 'Report_40', 'Report_41',
             'Report_42', 'Report_43', 'Report_44', 'Report_45', 'Report_46', 'Report_47', 'Report_48', 'Report_49',
             'Report_50', 'Report_51', 'Report_52', 'Report_53', 'Report_54', 'Report_55', 'Report_56', 'Report_57',
             'Report_58', 'Report_59', 'Report_60']
report_value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
                29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
                55, 56, 57, 58, 59, 60]

df = pd.DataFrame({'report_id': report_id, 'report_value': report_value})

sns.set(rc={'figure.figsize': (12, 60)})
ax = sns.barplot(y="report_id", x="report_value", data=df, palette="GnBu_d")
ax.tick_params(labelsize=3)
initialx = 0
for p in ax.patches:
    ax.text(p.get_width(), initialx + p.get_height() / 10, "{:1.0f}".format(p.get_width()))

    initialx += 1

plt.show()

Output Image is: IMAGE_OUTPUT

Cris_new
  • 55
  • 1
  • 10
  • 2
    Use the `fontsize` parameter of [`Axes.text`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.text.html). – BigBen Apr 26 '21 at 18:56
  • Please check this to see if it works for you ;) https://stackoverflow.com/questions/25328003/how-can-i-change-the-font-size-using-seaborn-facetgrid – Trovão Jan 31 '22 at 01:28

0 Answers0