0
0

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 1 year has passed since last update.

【Python】plotlyで円グラフ

Last updated at Posted at 2022-07-18
# -*- coding: utf-8 -*-
import pandas as pd  
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import datetime

dt_now = datetime.datetime.now()
dt_now_jst_aware = datetime.timedelta(days=7)

print(dt_now)
print(dt_now + dt_now_jst_aware)


df = pd.read_excel('test.xlsx', index_col=0)
df = df[df['hiduke'] <= datetime.datetime(2022, 7, 6)]
print(df[df['hiduke'] <= datetime.datetime(2022, 7, 6)])
fig = go.Figure()

fig.add_trace(
    go.Pie(labels = df['tantou'],
           values = df['kousu'])
)

fig.update_traces(
                hoverinfo='label+percent', # カーソルをあわせた時に表示される情報を設定
                textinfo='value',          # 円グラフ内に表示する文字情報を設定 (デフォルトだと割合)
                textfont_size=50,          # テキストのフォントの大きさを設定
                #marker=dict(line=dict(color='#000000', width=2)), #円グラフの 枠線(line),塗りつぶし色(color)などの設定
                textposition='inside', # テキストの表示位置 ("inside":グラフ内に表示)    
    
                #hole = .4, # 円グラフ内に空ける穴の大きさ (ドーナツ図へ)
                #pull = [0, 0.2, 0, 0, 0], # 一部要素だけを取り出すこともできる
)

fig.show()

参考

Pythonで任意の日付がその月の第何週目・何曜日かを取得 | note.nkmk.me
Pandas でデータフレームから特定の行・列を取得する – Python でデータサイエンス
Python で指定時間前(1日前、1年前など)、指定時間後(1日後、1年後)を求める方法
Plotly Pie Chart(円グラフ) 描き方 まとめ | AIリサーチコレクション

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?