cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
iamriz
Helper II
Helper II

How can I print Japanese Characters via Python Visual?

My data table contains one column of Japanese words, when I print this to a chart as data label using Python Visual, 3 rectangular characters ( ▯▯▯) will be printed instead. Kindly help how to print the JP characters properly. Thank you very much!

 

Excerpt of my Python Visual Script:

---

# dataset = pandas.DataFrame(1_ave, 1_slope, 顧客名)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:
import matplotlib.pyplot as plt
import json
import datetime
today = datetime.datetime.today()
current_month = today.month

fig, ax = plt.subplots(figsize=(18, 8)) # set chart size
ax.scatter(dataset["1_ave"], dataset["1_slope"], s=80, marker="s", color='r') #square
plt.xlabel('Average')
plt.ylabel('Slope')

ax.annotate("顧客名", (1, 1)) #Trying to print only one Japanese word here because putting all data will lead to script timeout

plt.show()

---

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@iamriz ,

 

This is not the issue in power bi, if you create a dataframe and run the code this issue also occurs. You may haven't configured the matplotlibrc, please download the .ttf font file and move the file to matplotlib/mpl-data/fonts/ttf then configure font.family, font.sans-serif and axes.unicode_minus like below:

font.family : sans-serif        
font.sans-serif : add the ttf file name here   
axes.unicode_minus : False

Finally run code below to reload the python environment:

from matplotlib.font_manager import _rebuild

_rebuild() #reload一下

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yuta-msft
Community Support
Community Support

@iamriz ,

 

This is not the issue in power bi, if you create a dataframe and run the code this issue also occurs. You may haven't configured the matplotlibrc, please download the .ttf font file and move the file to matplotlib/mpl-data/fonts/ttf then configure font.family, font.sans-serif and axes.unicode_minus like below:

font.family : sans-serif        
font.sans-serif : add the ttf file name here   
axes.unicode_minus : False

Finally run code below to reload the python environment:

from matplotlib.font_manager import _rebuild

_rebuild() #reload一下

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Thanks, @v-yuta-msft, sorry, my mistake I didn't check with pure python app using matplotlib.

Adding 

plt.rcParams['font.sans-serif'] = ['MS Gothic', 'sans-serif']
worked for me.
amitchandak
Super User IV
Super User IV

@iamriz ,

Refer, if this can help https://docs.python.org/3/howto/unicode.html



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Hi @amitchandak , I already tried str.encode() which returns b'\xe9\xa1\xa7\xe5\xae\xa2\xe5\x90\x8d', then when I decode it again, it will print the rectangle(garbage) characters. Actually, I thought that I do not need encoding and decoding because in Power BI data model, the JP characters perfectly show in utf-8 format. But I don't understand why it doesnt show up properly with Python Visual. Any advice? 

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors