我使用以下 Python 代码来生成旭日图:-
import plotly
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('CellUsageStats.csv',dtype={'Population':int},keep_default_na=False)
print(df.head(50))
fig = px.sunburst(df, path=['LibPrefix', 'MasterPrefixAbrHead', 'MasterPrefixAbrTail', 'Drive'], values='Population', color='Population', color_continuous_scale=px.colors.sequential.Inferno)
fig.update_traces(hovertemplate='Pattern: %{currentPath}%{label}<br>Matches: %{value}<br>Percent of <b>%{parent}</b>: %{percentParent:0.2%f}<br>Percent of <b>%{entry}</b>: %{percentEntry:0.2%f}<br>Percent of <b>%{root}</b>: %{percentRoot:0.2%f}')
fig.show()
plotly.offline.plot(fig, filename='sunburst.html')
Run Code Online (Sandbox Code Playgroud)
我有第二个 csv 文件,使用上面相同的代码来生成另一个旭日。如何将它们组合起来在同一个 html 输出中创建并排绘图?我发现...
https://plotly.com/python/sunburst-charts/
但是,我确实需要 px.sunburst 属性,并且上面链接中的示例使用 go.Sunburst,而不是 px.sunburst。是否有一种直接的方法可以从两组不同的数据生成并排图?
谢谢!
我正在填充这样的数据结构:
push @{$AvailTrackLocsTop{$VLayerName}}, $CurrentTrackLoc;
Run Code Online (Sandbox Code Playgroud)
其中$ VLayerName是一个字符串,例如m1,m2,m3等,而$ CurrentTrackLoc只是一个十进制数字。如果我在完全填充哈希之后使用Data :: Dumper打印哈希的内容,它将显示我期望的结果,例如:
$VAR1 = {
'm11' => [
'0.228',
'0.316',
'0.402',
'0.576',
'0.750',
'569.458',
'569.544',
'569.718',
'569.892'
]
};
Run Code Online (Sandbox Code Playgroud)
现在,我需要有效地拼接存储的十进制数字列表。我可以这样删除条目:
for (my $i = $c; $i <= $endc; $i++) {
delete $AvailTrackLocsTop{$VLayerName}->[$i];
}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,结果是一堆“ undef”条目,这些条目曾经存在数字,例如:
$VAR1 = {
'm11' => [
undef,
undef,
undef,
undef,
'0.750',
'569.458',
'569.544',
'569.718',
'569.892'
]
};
Run Code Online (Sandbox Code Playgroud)
但是,如何清除undef条目,以便我看到类似的内容?
$VAR1 = {
'm11' => [
'0.750',
'569.458',
'569.544',
'569.718',
'569.892'
]
};
Run Code Online (Sandbox Code Playgroud)
重要的是要注意,删除操作可以在数组中的任何位置进行,例如,索引33和100中的索引99。在哈希结构的上下文之外很容易拼接数组,但是在嵌入数组时,我很努力地操作数组在一个大哈希中。