実現したいこと
エラーの対処などではありません。plotlyのy軸の設定方法を工夫したいです。
Python
1import pandas as pd 2import numpy as np 3from datetime import timedelta 4import plotly.offline as offline 5import plotly.express as px 6import plotly.graph_objs as go 7 8td = datetime.timedelta(seconds=30) 9list=[['A',td*200], 10 ['B',td*1000], 11 ['C',td*500], 12 ['A',td*800], 13 ['C',td*10], 14 ['A',td*2000], 15 ['B',td*100], 16 ['B',td*40], 17 ['A',td*400], 18 ['A',td*20]] 19index = ["Row1", "Row2", "Row3", "Row4", "Row5"] 20columns =["Col1", "Col2"] 21df = pd.DataFrame(data=list).rename(columns={0:'col1',1:'col2'}) 22 23data = [go.Violin(y= df.query('col1=="A"')['col2'], 24 box_visible=True, points='all', name = "A"), 25 go.Violin(y= df.query('col1=="B"')['col2'], 26 box_visible=True, points='all', name = "B"), 27 go.Violin(y= df.query('col1=="C"')['col2'], 28 box_visible=True, points='all', name = "C")] 29layout = go.Layout( 30 xaxis = {'title' : 'x'}, 31 yaxis = {'title' : 'y'}, 32 legend= {'x':1, 'y':0.1}, 33 height=700) 34offline.iplot(go.Figure(data = data, layout = layout))
これによって表示されるグラフはバイオリンプロットとして適切に表示されます↓
ただ、y軸部分を見ると20T,40Tと表示されています。
これをT単位ではなく、1日や1時間単位、応用として2時間単位などを表示する方法を教えてほしいです!
yaxis部分をdictなどで分割して複雑な処理を書いていくのかなと思っていたのですが思いつきませんでした。
拙い文章ですいません!回答よろしくお願いします!
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2023/02/02 03:54