0

I am working on my thesis on Bnagla News headline relevancy. I want to visualize my data in pyplot graph. Here is an example of my code:

import matplotlib.pyplot as plt

column_name = 'News'

# Step 2: Calculate term frequency
sample_size = 50000
df_sample = df.sample(n=sample_size, random_state=42)

# Step 3: Calculate term frequency
term_frequency = df_sample[column_name].str.lower().str.split(expand=True).stack().value_counts()

# Step 4: Plot the top N terms with the highest frequencies in a bar chart
top_n = 10  # Change this value to plot more or fewer top terms
top_terms = term_frequency.head(top_n)

plt.figure(figsize=(10, 6))
plt.bar(top_terms.index, top_terms.values)
plt.xlabel('Terms')
plt.ylabel('Frequency')
plt.title(f'Top {top_n} Terms by Frequency (Sampled 50,000 rows)')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()

Here is how the graph look like: Plot terms is not showing properly In the image the bangla text which frequency is represented in the graph is not showing properly. Also my code is showing this warning: :22: UserWarning: Glyph 2451 (\N{BENGALI LETTER O}) missing from current font. plt.tight_layout() :22: UserWarning: Matplotlib currently does not support Bengali natively. plt.tight_layout() :22: UserWarning: Glyph 2469 (\N{BENGALI LETTER THA}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2503 (\N{BENGALI VOWEL SIGN E}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2453 (\N{BENGALI LETTER KA}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2480 (\N{BENGALI LETTER RA}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2447 (\N{BENGALI LETTER E}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2494 (\N{BENGALI VOWEL SIGN AA}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2507 (\N{BENGALI VOWEL SIGN O}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2472 (\N{BENGALI LETTER NA}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2439 (\N{BENGALI LETTER I}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2476 (\N{BENGALI LETTER BA}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2434 (\N{BENGALI SIGN ANUSVARA}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2489 (\N{BENGALI LETTER HA}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2460 (\N{BENGALI LETTER JA}) missing from current font. plt.tight_layout() :22: UserWarning: Glyph 2482 (\N{BENGALI LETTER LA}) missing from current font. plt.tight_layout() /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2451 (\N{BENGALI LETTER O}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Matplotlib currently does not support Bengali natively. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2469 (\N{BENGALI LETTER THA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2503 (\N{BENGALI VOWEL SIGN E}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2453 (\N{BENGALI LETTER KA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2480 (\N{BENGALI LETTER RA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2447 (\N{BENGALI LETTER E}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2494 (\N{BENGALI VOWEL SIGN AA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2507 (\N{BENGALI VOWEL SIGN O}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2472 (\N{BENGALI LETTER NA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2439 (\N{BENGALI LETTER I}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2476 (\N{BENGALI LETTER BA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2434 (\N{BENGALI SIGN ANUSVARA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2489 (\N{BENGALI LETTER HA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2460 (\N{BENGALI LETTER JA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.10/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 2482 (\N{BENGALI LETTER LA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw)

I want a proper solution that will visualize the Bangla Text in the plot. Which font I should include and why this is hapening? I want the solution to progress my thesis.

  • As you have been clearly informed and already observed, "why this is happening" is that the default font that `matplotlib` will use for labels cannot show Bengali letters; it just doesn't have any symbols for them. The only possible *on-topic* question remaining is "how do I change the font?", which is a duplicate. If you want to know "which font should I use?", that is off topic for Stack Overflow; it is a question about fonts, not a question about programming. (If you need to know how to install a font, that is a question about using a computer, still not a question about programming.) – Karl Knechtel Jul 25 '23 at 05:33
  • (Please also read: [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592)) – Karl Knechtel Jul 25 '23 at 05:35
  • There are two issues: 1) the font being used does not have bangla characters – Andj Sep 03 '23 at 04:00

0 Answers0