Python 我们如何在Plotly中的子地块中制作镶嵌面网格?
我们如何在Plotly中的子地块中制作镶嵌面网格?例如,我想将Python 我们如何在Plotly中的子地块中制作镶嵌面网格?,python,plotly,subplot,facet-grid,Python,Plotly,Subplot,Facet Grid,我们如何在Plotly中的子地块中制作镶嵌面网格?例如,我想将总账单与小费在子批次中绘制五次。我厌倦了做以下事情: import plotly.plotly as py import plotly.figure_factory as ff from plotly import tools subfigs = tools.make_subplots(rows= 5, cols=1) import pandas as pd tips = pd.read_csv('https://raw.gith
总账单
与小费
在子批次中绘制五次。我厌倦了做以下事情:
import plotly.plotly as py
import plotly.figure_factory as ff
from plotly import tools
subfigs = tools.make_subplots(rows= 5, cols=1)
import pandas as pd
tips = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/tips.csv')
for i in enumerate(tips.columns.tolist()):
fig = ff.create_facet_grid(
tips,
x='total_bill',
y='tip',
color_name='sex',
show_boxes=False,
marker={'size': 10, 'opacity': 1.0},
colormap={'Male': 'rgb(165, 242, 242)', 'Female': 'rgb(253, 174, 216)'}
)
subfigs.append_trace(fig, i+1, 1)
pyo.iplot(fig)
这不起作用,因为地物工厂创建的镶嵌面栅格不被视为跟踪。有没有办法做到这一点?答案没有帮助,因为在我看来,
袖扣
不接受平面网格这里发生了很多事情
enumerate
提供了一个元组列表,如果您只想通过可以使用的索引进行迭代
for i in range(tips.columns.size):
否则,您可以通过执行
for i, col in enumerate(tips.columns):
图
,其中包含跟踪
,在其数据
列表中。您可以通过索引访问create\u facet\u grid
方法生成的一条记录道:
subfig.append_trace(fig['data'][index_of_the_trace], n1, n2)
tips = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/tips.csv')
current_column = 'sex'
subfigs = tools.make_subplots(
rows = tips[current_column].nunique(),
cols = 1
)
fig = ff.create_facet_grid(
tips,
x = 'total_bill',
y = 'tip',
facet_row = current_column,
color_name = 'sex',
show_boxes = False,
marker = {'size': 10, 'opacity': 1.0},
colormap = {
'Male': 'rgb(165, 242, 242)',
'Female': 'rgb(253, 174, 216)'
}
)
for i in range(tips[current_column].nunique()):
subfigs.append_trace(fig['data'][i], i+1, 1)
py.iplot(fig)