Skip to main content
 首页 » 编程设计

python之将多个表添加到 plotly plot

2025年05月04日19qlqwjy

我尽我最大的努力想出一种在相同的子图上绘制两个表的方法,但似乎无法通过这一部分。搜索一直没有成果。

fig = tools.make_subplots(rows = 2, cols=1, subplot_titles=('Continious  
 
Features','Catagorical Features')) 
 
cont_table = FF.create_table(cont_data_matrix, index= True,index_title='Feature') 
cat_table = FF.create_table(cont_data_matrix, index= True,index_title='Feature') 
 
cont_table['figure'].extend() 
 
fig.append_trace(cont_table, 1,1) 
fig.append_trace(cont_table, 2,1) 
 
py.plot(fig) 

请您参考如下方法:

我强烈推荐使用 cufflinks 库,它将 pandas 和 plotly 联系在一起,为 pandas 数据帧提供 iplot()命令。 https://plot.ly/ipython-notebooks/cufflinks/

import cufflinks as cf 
import pandas as pd 
 
table.iplot(kind='scatter', subplots=True, shape=(2,1), filename='cufflinks_test') 

所以现在的诀窍是设置表。您希望每个跟踪的数据位于不同的列中,并且索引对应于 X 值。 pivot_table() 对于将数据调整为正确的形状非常有用。

如果您为 cont_table 和 cat_table 包含一些虚拟数据,我可以提供代码来组合它们,以便上面的代码工作。