python 如何删除绘图工具中的绘图边距,make_subplots?

k4aesqcs  于 2023-01-24  发布在  Python
关注(0)|答案(2)|浏览(162)

我想删除子图的边距:工具。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)
mfpqipee

mfpqipee1#

Ok间接在袖扣 Package 纸上找到的:):tools_by_cufflink

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

e3bfsja22#

用这个吧,我想这个可以满足你的要求
图更新布局(字体大小=16,边距=dict(l=0,r=0,B=0,t=0),Map框样式=“开放街道Map”)

相关问题