Displaying Unicode characters like করে in matplotlib

I want to plot the text "কৃষক জমিতে ধান চাষ করে", with matplotlib, what should I do ...?

I tried to leak, but it didn't work.

s = u"কৃষক জমিতে ধান চাষ করে"
x = 0.2
y = 0.2
matplotlib.pyplot.text(x, y, s)

      

+3


source to share


1 answer


Python3

This should work with a font that contains these Unicode characters. I used kalpurush to cover Unicodes Bangla. You can pass the font in the matplotlib

following way:

import matplotlib.font_manager as fm
import matplotlib.pyplot as plt

prop = fm.FontProperties(fname='kalpurush.ttf')
s = u"কৃষক জমিতে ধান চাষ করে"
x = 0.2
y = 0.2
plt.text(x, y, s, fontproperties=prop)
plt.show()

      

enter image description here



Bonus: Python2

For python 2, this is very easy. just add this to the top of the file:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

      

+2


source







All Articles