0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

matplotlibの設定

Posted at

準備

まずはmatplotlibをインポートし、適当なグラフを描く

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,2*np.pi)
y = np.sin(x)
plt.plot(x,y)

output_4_1.png

各種設定

Grid線を表示

Grid線の表示

plt.plot(x,y)
plt.grid()

output_6_0.png

軸ラベルの設定

plt.plot(x,y)
plt.xlabel("x")
plt.ylabel("y")

output_8_1.png

表示範囲の変更

plt.plot(x,y)
plt.xlim([0,1])
plt.ylim([0,1])

output_10_1.png

スタイルシート

matplotlibにはあらかじめ用意されたスタイルシートがあり、それらを用いることもできる。使用可能なスタイルシートを調べるには次のようにします。

print(plt.style.available)
['bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark-palette', 'seaborn-dark', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'seaborn', 'Solarize_Light2', 'tableau-colorblind10', '_classic_test']

スタイルシートを使うときは、以下のように記述すると、全体のスタイルに影響を及ぼさないように出来ます。

with plt.style.context('dark_background'):
    plt.plot(x,y)

output_14_0.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?