Python的Plotly庫對於數據可視化和簡單,輕鬆地理解數據非常有用。
figure_factory.create_bullet
此方法用於創建項目符號圖。此函數可以同時使用數據幀或字典序列。
用法:plotly.figure_factory.create_bullet(data, markers=None, measures=None, ranges=None, subtitles=None, titles=None, orientation=’h’, **layout_options)
參數:
數據:字典或 Pandas DataFrame的列表/元組。
標記:每個子圖中標記的列名或字典鍵。
度量:此條通常表示性能的量化度量,通常是兩個值[a,b]的列表,默認情況下是每個子圖的前景中的藍色條。
範圍:此參數通常是一個3項列表[不好,可以,很好]。它們對應於每個圖表背景中的灰色條。
字幕:每個子圖圖表的字幕的列名或字典鍵。
title((str))-每個子圖圖表的主標簽的列名或字典鍵。
範例1:
Python3
import plotly.figure_factory as ff
data = [
{"label":"revenue",
"sublabel":"us$, in thousands",
"range":[150, 225, 300],
"performance":[220,270],
"point":[250]},
{"label":"Profit",
"sublabel":"%",
"range":[20, 25, 30],
"performance":[21, 23],
"point":[26]},
{"label":"Order Size",
"sublabel":"US$, average",
"range":[350, 500, 600],
"performance":[100,320],
"point":[550]},
{"label":"New Customers",
"sublabel":"count",
"range":[1400, 2000, 2500],
"performance":[1000, 1650],
"point":[2100]},
{"label":"Satisfaction",
"sublabel":"out of 5",
"range":[3.5, 4.25, 5],
"performance":[3.2, 4.7],
"point":[4.4]}
]
fig = ff.create_bullet(
data, titles='label',
subtitles='sublabel',
markers='point',
measures='performance',
ranges='range',
orientation='h',
title='my simple bullet chart'
)
fig.show()
輸出:
範例2:將 DataFrame 與顏色一起使用
Python3
import plotly.figure_factory as ff
import pandas as pd
data = [
{"title":"Revenue",
"subtitle":"US$, in thousands",
"ranges":[150, 225, 300],
"measures":[220, 270],
"markers":[250]},
{"title":"Profit",
"subtitle":"%",
"ranges":[20, 25, 30],
"measures":[21, 23],
"markers":[26]},
{"title":"Order Size",
"subtitle":"US$, average",
"ranges":[350, 500, 600],
"measures":[100, 320],
"markers":[550]},
{"title":"New Customers",
"subtitle":"count",
"ranges":[1400, 2000, 2500],
"measures":[1000, 1650],
"markers":[2100]},
{"title":"Satisfaction",
"subtitle":"out of 5",
"ranges":[3.5, 4.25, 5],
"measures":[3.2, 4.7],
"markers":[4.4]}
]
fig = ff.create_bullet(
data, titles='title',
markers='markers',
measures='measures',
orientation='v',
measure_colors=['rgb(14, 52, 75)', 'rgb(31, 141, 127)'],
scatter_options={'marker':{'symbol':'circle'}},
width=700)
fig.show()
輸出:
相關用法
注:本文由純淨天空篩選整理自deepanshumehra1410大神的英文原創作品 plotly.figure_factory.create_bullet() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。