如何在plotly tools.make_subplots中删除绘图边距?

时间:2018-05-22 11:23:49

标签: python plotly plotly-dash

我想删除子图的边距:tools.make_subplots(参见代码图g01)。 horizontal_spacingvertical_spacing无效。

对于正常情节,我可以用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)

1 个答案:

答案 0 :(得分:0)

好吧发现它间接在袖扣包装:): tools_by_cufflink

fig['layout'].update(margin=dict(l=0,r=0,b=0,t=0))