这是来自plotly官网的一个例子:
输入输出说明
画图数据
head5.png单个样品饼图
newplot.png代码说明:
import pandas as pd
import re
import plotly
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
df = pd.read_table('feature-table.tsv')
## 获取单个pie图
index = 'OTU.S4'
df[index] = df[index]/df[index].sum()
df_plot = pd.DataFrame({'name':df['#OTU ID'], 'per':df[index]})
df_plot['name'] = df_plot['name'].str.split(";").apply(lambda x: x[-1])
df_plot.loc[df_plot['per'] < 0.01, 'name'] = 'Others' # Represent only large countries
fig = px.pie(df_plot, values='per', names='name', title='')
fig.update_layout(height=400, width=600)
fig.show()
网友评论