How to render the Nepali or Hindi text as label?

 This method allows you to plot directly using specific fonts. You can choose the font of your choice, as here the Mangal font is used according to your choice. All you have to do is apply the font properties to each label.

# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
from matplotlib.font_manager import FontProperties


font_prop = FontProperties(fname='Mangal.ttf', size=18)


figure(num=None, figsize=(15, 6), dpi=80, facecolor='w', edgecolor='k')
a = [('सरकारले', 3410), ('अर्ब', 3143), ('आर्थिक', 3026), ('रुपैयाँ', 2965),
     ('कारण', 2758), ('काम', 2745), ('व्यवस्था', 2683), ('समेत', 2580)]
b = dict(a)

ax = plt.subplot()

val_val = b.values()
key_val = b.keys()
br = plt.bar(key_val, val_val)


for label in (ax.get_xticklabels() + ax.get_yticklabels()):
    label.set_fontproperties(font_prop)
    label.set_fontsize(15)  # Size here overrides font_prop


plt.title("नेपाली भाषामा शीर्षक", fontproperties=font_prop,
          size=22, verticalalignment='bottom')  # Size here overrides font_prop
plt.xlabel("लेबलहरू", fontproperties=font_prop)
plt.ylabel("लेबलहरू", fontproperties=font_prop)


plt.show()

I also gave titles and labels using Google Translate. I don't know Nepali, apology if the translation is stupid.

python matplotlib bar with unicode


 https://stackoverflow.com/questions/64300662/how-to-render-the-nepali-or-hindi-text-as-label



Comments

Popular posts from this blog

OpenCV Video Capturing Error : CvCapture_MSMF::initStream Failed to set mediaType

Face Attendance

Official genuine JetBrains code pycharm Key