Skip to content

Instantly share code, notes, and snippets.

@kuo77122
Last active September 2, 2020 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuo77122/5a31b3ccb3533db39dc00ffa4499f03c to your computer and use it in GitHub Desktop.
Save kuo77122/5a31b3ccb3533db39dc00ffa4499f03c to your computer and use it in GitHub Desktop.
[Jupyter Notebook Tips] #jupyter

1. Maximum the width of cell

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:90% !important; }</style>"))

2. Display none ASCII words with matplotlib

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

plt.rcParams['axes.unicode_minus']=False
# Say, "the default sans-serif font is COMIC SANS"
plt.rcParams['font.sans-serif'] = ["Taipei Sans TC Beta"]
# Then, "ALWAYS use sans-serif fonts"
plt.rcParams['font.family'] = "sans-serif"
plt.rcParams.update({'font.size': 22})

plt.xlabel("あそこ") # 步驟三
plt.ylabel("y軸")
plt.title("標題")
plt.show()

another method https://stackoverflow.com/questions/23197124/display-non-ascii-japanese-characters-in-pandas-plot-legend

https://albertauyeung.github.io/2020/03/15/matplotlib-cjk-fonts.html

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager

df = pd.DataFrame( data=np.random.random( (2,2) ), columns=[u'é',u'日本'] )
ax = df.plot()
legend = ax.legend()
font = font_manager.FontProperties(fname='/Users/user/Downloads/IPAfont00303/ipag.ttf')

for text in legend.texts:
    text.set_font_properties(font)

plt.show()

3. Display full rows of dataframe

pd.set_option('display.max_column',None)
pd.set_option('display.max_rows',None)
pd.set_option('display.max_seq_items',None)
pd.set_option('display.max_colwidth', 500)
pd.set_option('expand_frame_repr', True)

4. Matplotlib plot 2X resolution on Retina Screen

from IPython.display import set_matplotlib_formats
set_matplotlib_formats('retina')

5. Change the JyputerLab's Browser Tab Title

jupyter lab build --name='my_name'

6. Control figure size with pandas plot

df.plot(figsize=(10,5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment