我一直在尝试使用plotly并排绘制表格和散点图,但很长一段时间都无济于事。我们怎样才能做到这一点?
如何在plotly3.6中绘制表格和散点图?
到目前为止我已经尝试过:
import numpy as np
import pandas as pd
import seaborn as sns
sns.set(color_codes=True)
import matplotlib.pyplot as plt
%matplotlib inline
import plotly
import plotly.offline as py
import plotly.plotly as pyp
import plotly.graph_objs as go
import plotly.figure_factory as ff
import plotly.tools as tls
from plotly.offline import plot, iplot, init_notebook_mode
init_notebook_mode(connected=False)
# subplots table
fig = tls.make_subplots(rows=1, cols=2, shared_xaxes=True)
trace1 = go.Scatter(x=[1,2,3],y=[1,2,3])
df = pd.DataFrame({'name':list('ABC'),
'salary': [1000,2000,3000]})
table = ff.create_table(df)
fig.append_trace(table, 1, 2)
py.iplot(fig)
但这不起作用。
然而,
iplot(table)
有效。
如何解决这个问题?
最佳答案
您已经很接近了,但忘记了规范元素。另外,您必须使用 row=#
和 col=#
在 .add_trace()
中指定定位,希望这会有所帮助。
from plotly.subplots import make_subplots
columns =['one','two']
cellValues =['first piece of data', 'second piece of data']
figure = make_subplots(
rows = 1, cols =2,
specs=[[{"type":"table"},{"type" : "scatter"}]]
)
figure.add_trace(go.Table(header=dict(
values = columns
#other elements here
),cells=dict(
values = cellValues
), row=1, col=1
)
figure.add_trace(go.Scatter(x=[1,2,3],y=[1,2,3]),row=1,col=2)
)
关于python - 如何在plotly3(不是plotly4)中并排绘制表格和散点图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57317847/