我想删除子图的边距:tools.make_subplots(参见代码图 g01)。 horizontal_spacing
或 vertical_spacing
没有帮助。
对于正常的 plotly ,我可以使用 go.Margin(l=0, r=0 ..) 来做到这一点。 (参见代码中的图 g11)。
我只想要子图的相同行为。任何人,任何想法?
import dash
from dash.dependencies import Output, Event
import dash_core_components as dcc
import dash_html_components as html
import base64
from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go
from collections import deque
import numpy as np
import random
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Graph(id='g01',),
dcc.Interval(id='graph-update', interval= 1000 * 1),
dcc.Graph(id='g11',),
dcc.Interval(id='graph-update', interval= 1000 * 1),
], style={
'margin-left' : '0',
'margin-right' : '0',
'padding-left' : '0',
'padding-right' : '0',
})
@app.callback(Output('g01', 'figure'),
events=[Event('graph-update', 'interval')])
def update_graph_bar():
trace1 = go.Bar( x=[1, 2, 3], y=[4, 5, 6], showlegend=False)
trace2 = go.Scatter( x=[1, 2, 3], y=[4, 5, 6], showlegend=False)
fig = tools.make_subplots(rows = 1, cols = 2, specs = [[{}, {}]],
horizontal_spacing = 0.00,
vertical_spacing = 0.00,
)
fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 2)
fig['layout'].update(height=250, width=660,)
return fig
@app.callback(Output('g11', 'figure'),
events=[Event('graph-update', 'interval')])
def update_graph_bar():
data = [
go.Scatter(
x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
y=[0, 1, 2, 3, 4, 5, 6, 7, 8]
)
]
layout = go.Layout(
autosize=False,
width=500,
height=500,
margin=go.Margin(
l=0,
r=0,
b=0,
t=0,
pad=0
),
paper_bgcolor= '#7f7f7f',
plot_bgcolor= '#c7c7c7',
)
fig = go.Figure(data=data, layout=layout)
return fig
IP = '192.168.1.1'
if __name__ == '__main__':
app.run_server(debug=True, host=IP,port= 1111)
最佳答案
好的,在袖扣 wrapper 中间接找到了它:):
tools_by_cufflink
fig['layout'].update(margin=dict(l=0,r=0,b=0,t=0))
关于python - 如何在 plotly tools.make_subplots 中删除绘图边距?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50466450/