LoginSignup
0
1

Pythonの便利技と注意点:Jupyter編

Last updated at Posted at 2022-08-25

目次に戻る

JupyterとRをJupyter Notebookで使う時の注意

こちらに別途記事を記載しました:https://qiita.com/yuta-sanjyo/items/7fda2059408e0e604413

グラフの日本語文字化けを防ぐ

フォントを指定しないと日本語タイトルがこのように文字化けする
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns

plt.plot([0, 100, 200], [100, 0, 200])
plt.title("タイトル")
plt.show()

Pythonグラフ文字化け.png

Windowsの場合:Meiryo, Yu Gothic, Hiragino Maru Gothic Pro等を設定する
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(font=["Meiryo", "Yu Gothic", "Hiragino Maru Gothic Pro"])

plt.plot([0, 100, 200], [100, 0, 200])
plt.title("タイトル")
plt.show()

Pythonグラフ文字化けしない.png

Ubuntuの場合:Noto Serif CJK JP, Noto Sans CJK JPを設定する
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(font=["Noto Serif CJK JP", "Noto Sans CJK JP"])

plt.plot([0, 100, 200], [100, 0, 200])
plt.title("タイトル")
plt.show()

image.png

conda installでパッケージがない場合

-cでconda-forgeを指定するとインストールできる場合がある
$ conda install -c conda-forge <パッケージ名>

ライブラリや関数の詳細を表示する

「?」をつけるとDocStringが表示される
import logging
logging.debug?
出力結果
Signature: logging.debug(msg, *args, **kwargs)
Docstring:
Log a message with severity 'DEBUG' on the root logger. If the logger has
no handlers, call basicConfig() to add a console handler with a pre-defined
format.
File:      c:\users\<user_name>\.conda\envs\<virtual_environment_name>\lib\logging\__init__.py
Type:      function
「??」をつけるとsourceが表示される
import logging
logging.debug??
出力結果
Signature: logging.debug(msg, *args, **kwargs)
Source:   
def debug(msg, *args, **kwargs):
    """
    Log a message with severity 'DEBUG' on the root logger. If the logger has
    no handlers, call basicConfig() to add a console handler with a pre-defined
    format.
    """
    if len(root.handlers) == 0:
        basicConfig()
    root.debug(msg, *args, **kwargs)
File:      c:\users\<user_name>\.conda\envs\<virtual_environment_name>\lib\logging\__init__.py
Type:      function

目次に戻る

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1