注釈の追加

Pythonで学ぶPlotlyによるデータ可視化入門

Alex Scriven

Data Scientist

注釈とは?

  • プロットに追加する補足のテキストやデータ

$$

  1. 特定のデータ点を強調
  2. プロットに注記を追加

データ連動の注釈

Pythonで学ぶPlotlyによるデータ可視化入門

注釈の作成

$$

  • add_annotation() の利用
    • 単一の注釈を追加

$$

  • update_layout()annotations 引数を利用
    • 注釈オブジェクトのリストを受け付ける
Pythonで学ぶPlotlyによるデータ可視化入門

主要な注釈引数

  • text - 表示するテキスト
    • 変数を含められる

$$

  • xy - 注釈の位置

$$

  • showarrow = True/False - 矢印の有無
    • 矢印はカスタマイズ可能

$$

🛑 絶対配置は注意。データが変わると重なることがあります

Pythonで学ぶPlotlyによるデータ可視化入門

注釈の位置指定

 

  • 既定では xy はプロット内のデータ値

$$

  • xrefyrefpaper にすると注釈を絶対配置
    • このとき xy はプロット領域で 0〜1 の割合
    • (x=0.5, y=0.5) は中央
Pythonで学ぶPlotlyによるデータ可視化入門

データ連動の注釈

 

  • 散布図で自社を強調
my_annotation = dict(
    x=215111, y=449000,

showarrow=True, arrowhead=3,
text="Our company is doing well", font=dict(size=10, color="black") )
fig.update_layout(annotations=[my_annotation]) fig.show()

 

$$

データ連動の注釈

Pythonで学ぶPlotlyによるデータ可視化入門

浮動注釈

$$

float_annotation = dict(
    xref="paper", yref="paper",

x=0.5, y=0.8,
showarrow=False, text="You should <b>BUY</b>", font=dict(size=15, color="black"), bgcolor="rgb(255,0,0)" )

 

浮動注釈

Pythonで学ぶPlotlyによるデータ可視化入門

練習しましょう!

Pythonで学ぶPlotlyによるデータ可視化入門

Preparing Video For Download...