[Jupyter Notebook memo] Display kanji with matplotlib

Introduction

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.

code

Loading the library

#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

Loading Boston dataset for sample 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())

Screen display code sample

#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()

Result sample (from Google Colaboratory)

スクリーンショット 2020-01-09 8.54.25.png

Recommended Posts

[Jupyter Notebook memo] Display kanji with matplotlib
Jupyter Notebook memo
Install matplotlib and display graph on Jupyter Notebook
Graph drawing with jupyter (ipython notebook) + matplotlib + vagrant
Using Graphviz with Jupyter Notebook
Display HTML in Jupyter notebook
Use pip with Jupyter Notebook
Use Cython with Jupyter Notebook
Play with Jupyter Notebook (IPython Notebook)
A memo that uses an interactive display mode like Jupyter notebook with VSCode + Python
[Memo] Display Jupyter Notebook on PC in monospaced font (Mac)
Write charts in real time with Matplotlib on Jupyter notebook
Inference & result display with Tensorflow + matplotlib
Python memo Anaconda x Jupyter Notebook
Visualize decision trees with jupyter notebook
Make a sound with Jupyter notebook
[MEMO] [Development environment construction] Jupyter Notebook
Use markdown with jupyter notebook (with shortcut)
Add more kernels with Jupyter Notebook
Convenient analysis with Pandas + Jupyter notebook
Matplotlib memo
Use nb extensions with Anaconda's Jupyter notebook
Use apache Spark with jupyter notebook (IPython notebook)
Jupyter Notebook does not show matplotlib graphs
I want to blog with Jupyter Notebook
Use Jupyter Lab and Jupyter Notebook with EC2
Try SVM with scikit-learn on Jupyter Notebook
Display Japanese graphs with VS Code + matplotlib
How to use jupyter notebook with ABCI
Display histogram / scatter plot on Jupyter Notebook
Linking python and JavaScript with jupyter notebook
Display markers above the border with matplotlib
Rich cell output with Jupyter Notebook (IPython)
How to debug with Jupyter or iPython Notebook
Introducing Jupyter Notebook
When Html cannot be output with Jupyter Notebook
Analytical environment construction with Docker (jupyter notebook + PostgreSQL)
Verify NLC accuracy with Watson Studio's Jupyter Notebook
I want to display multiple images with matplotlib.
Interactively display algebraic curves with Python and Jupyter
Powerful Jupyter Notebook
Enable Jupyter Notebook with conda on remote server
Try using conda virtual environment with Jupyter Notebook
Simply display a line graph on Jupyter Notebook
Fill the browser with the width of Jupyter Notebook
Animation with matplotlib
Japanese with matplotlib
How to display images continuously with matplotlib Note
Jupyter notebook password
Animation with matplotlib
Histogram with matplotlib
Animate with matplotlib
You can now display slides with nbviewer! [Jupyter]
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Drawing a tree structure with D3.js in Jupyter Notebook
Import specific cells from other notebooks with Jupyter notebook
EC2 provisioning with Vagrant + Jupyter (IPython Notebook) on Docker
Display the graph while changing the parameters with PySimpleGUI + Matplotlib
Multiple selections with Jupyter
Candlestick with plotly + Jupyter
Get started Jupyter Notebook