How to display Kanji with matplotlib on Jypyter Notenook Memo. I used to use a more complicated method, but this one is simpler. It has been confirmed to work with Google Colaboratory and Watson Studio.
#Introduction of required libraries
!pip install japanize-matplotlib | tail -n 1
#Import of required libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#Japanese localization
import japanize_matplotlib #Japanese matplotlib
import seaborn as sns
sns.set(font="IPAexGothic") #Japanese font settings
#Data frame display function
from IPython.display import display
#Boston dataset loading
from sklearn.datasets import load_boston
boston = load_boston()
df = pd.DataFrame(boston.data, columns=boston.feature_names)
df.insert(0, 'PRICE', boston.target)
#Check the result
display(df.head())
#graph display
plt.figure(figsize=(6,6))
plt.scatter(df.RM, df.PRICE)
plt.xlabel('number of rooms')
plt.ylabel('price')
plt.title('Scatter plot display of Boston dataset')
plt.show()
Recommended Posts