• home
  • about
  • 全ての投稿
  • ソフトウェア・ハードウェアの設定のまとめ
  • 分析関連のまとめ
  • ヘルスケア関連のまとめ
  • 生涯学習関連のまとめ

plotly

date: 2021-08-02 excerpt: plotlyの使い方

tag: 可視化visualizationspythonplotly


plotlyの使い方

概要

  • jupyter, kaggle notebookで使用できる可視化ライブラリ
  • JSで描画されるのでマウスオーバーで値が出てわかりやすい

インストール

$ pip install plotly

描画エンジンの設定

  • jupyterlabで使用する場合はiframeで挙動の確認ができる
import plotly.io as pio
pio.renderers.default = 'iframe'  # または 'jupyterlab', 'notebook', 'browser' に変更

具体例

バープロット

基本

import plotly.express as px

fig = px.bar(df, x="JobTile", y="Count")
fig.show()

バーの内容を標示する

import plotly.express as px

x = df.groupby(["JobTitle", "Country"], as_index=False).Count.sum()
fig = px.bar(x, x="JobTitle", y="Count", color="Country")
display(fig)

ラインプロット

基本

import plotly.express as px
x = df.groupby(['JobTitle'], as_index=False).Count.sum()
fig = px.line(x, x='JobTitle', y='Count')
fig.show()

各要素毎に分けて標示する

import plotly.express as px

x = df.groupby(['JobTitle', 'Country'], as_index=False).Count.sum()
fig = px.line(x, x='JobTitle', y='Count', color='Country')
fig.show()

極線図(line polor)

  • 使い方はラインプロットとほぼ同じ
import plotly.express as px
x = df.groupby(['JobTitle', 'Country'], as_index=False).Count.sum()
fig = px.line_polar(x, theta='JobTitle', r='Count', color='Country')
fig.show()

参考

  • How to Create Award Winning Data Visualizations/Kaggle


可視化visualizationspythonplotly Share Tweet