Skip to content

Tamil font is rendered in a wrong manner in matplotlib #8481

@Pavan-RESTs

Description

@Pavan-RESTs

I have been working on with a project in matplotlib.
I'm trying to display tamil texts in a pie chart.
I did downloaded and specified the appropriate font paths (In my case Brahmini, Noto sans tamil, Tiro, etc...)
Everything does render the tamil font but it is completely in a wrong manner.
Figure(1) is the actual rendering.
Figure(2) is the required rendering.

CODING

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

font_path = r"Fonts\Tamil Font.TTF" //Replace with a tamil font path

tamil_font = FontProperties(fname=font_path) 

sizes = [25, 35, 20, 20]  
labels = ['எனக்கு ', 'மின்விசிறி', 'கலை', 'வாழைப்பழம்']  
colors = ['#ff9999','#66b3ff','#99ff99','#ffcc99']

fig, ax = plt.subplots()
wedges, texts, autotexts = ax.pie(sizes, colors=colors, autopct='%1.1f%%', startangle=90)

ax.axis('equal')

for i, autotext in enumerate(autotexts):
    autotext.set_text(labels[i])  
    autotext.set_color("black")  
    autotext.set_fontsize(12)  
    autotext.set_fontproperties(tamil_font)  

for text in texts:
    text.set_fontproperties(tamil_font)

plt.show()

Screenshot 2024-10-18 024111
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions