02グラフのスタイルを設定する
#linewidth 绘制线条宽度
plt.plot(a,s, linewidth = 6)
#添加x,y轴名称
plt.xlabel('x')
plt.ylabel('y = x^2')
#给图标添加图名
plt.rcParams['font.sans-serif'] = ['SimHei'] # 中文下的字体格式进行修改对
plt.title('多点绘制')
plt.show()
さまざまなスタイルと色で線を引く
そして、凡例()メソッドを使用して、ラベルパラメーターをプロットに追加します。
x = np.linspace(0, 10, 100)
plt.plot(x, x+0, '--g', label = "--g")
plt.plot(x, x+1, '-.r', label = '-.r')
plt.plot(x, x+2, ':b', label = ':b')
plt.plot(x, x+3, ',c', label = ',c')
plt.plot(x, x+4, '*y', label = '*y')
plt.plot(x, x+5, '.k', label = '.k')
plt.legend(loc = 'lower right', # 默认在左上角即 upper left 可以通过loc进行修改
fancybox = True, # 边框
framealpha = 0.5, # 透明度
shadow = True, # 阴影
borderpad = 1) # 边框宽度
plt.show()
書式文字
フォーマット | スタイル |
---|---|
「-」 | 実線スタイル |
「–」 | ダッシュスタイル |
「-」 | 点線スタイル |
「:」 | 点線スタイル |
「。」 | ドットマーク |
「、」 | ピクセルマーク |
「o」 | 丸印 |
「v」 | 逆三角形のマーク |
「^」 | 正三角マーク |
「<」 | 左三角マーク |
'>' | 直角三角形のマーク |
「1」 | 下矢印マーク |
「2」 | 上矢印マーク |
「3」 | 左矢印マーク |
「4」 | 右矢印マーク |
's' | スクエアマーク |
「p」 | ペンタゴンマーク |
「*」 | スターマーク |
「h」 | 六角マーク1 |
「H」 | 六角マーク2 |
「+」 | プラス記号 |
'バツ' | Xマーク |
「D」 | ダイヤモンドマーク |
「d」 | 細いダイヤマーク |
'|' | 縦線マーキング |
「_」 | 横マーク |
一般的な色
コード | 色 |
---|---|
「b」 | 青 |
「g」 | 緑 |
「r」 | 赤 |
「c」 | 青色 |
「m」 | マゼンタ |
「そして」 | 黄 |
「k」 | 黒 |
「w」 | 白 |
Matplotlib カラーディスプレイ
`python
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.colors as colors
import math
fig = plt.figure()
ax = fig.add_subplot(111)
ratio = 1.0 / 3.0
count = math.ceil(math.sqrt(len(colors.cnames)))
x_count = count * ratio
y_count = count / ratio
x = 0
y = 0
w = 1 / x_count
h = 1 / y_count
for c in colors.cnames:
pos = (x / x_count, y / y_count)
ax.add_patch(patches.Rectangle(pos, w, h, color=c))
ax.annotate(c, xy=pos)
if y >= y_count-1:
x += 1
y = 0
else:
y += 1
plt.show()
詳しくはMatplotlibの公式サイトの参考資料をご覧ください