Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Plotly:如何检查和更改Plotly图形?_Python_Plotly_Plotly Python - Fatal编程技术网

Python Plotly:如何检查和更改Plotly图形?

Python Plotly:如何检查和更改Plotly图形?,python,plotly,plotly-python,Python,Plotly,Plotly Python,相关问题已经被问过了,例如: 但这些问题的答案受到限制,因为并非所有参数都可以通过Python获得,这意味着真正的答案隐藏在JavaScript中的某个地方。但对于较新版本的plotly,如何检查和编辑plotly地物?例如,您如何确定图形的背景颜色?然后改变它?从上面的第二个链接中,您可以看到fig.show和print(fig)将显示有关图形结构的一些细节。但肯定不是全部。下面的代码段将生成以下绘图: 绘图: 代码: 运行fig.show将以dict的形式部分显示图形的结构: &l

相关问题已经被问过了,例如:

但这些问题的答案受到限制,因为并非所有参数都可以通过Python获得,这意味着真正的答案隐藏在JavaScript中的某个地方。但对于较新版本的plotly,如何检查和编辑plotly地物?例如,您如何确定图形的背景颜色?然后改变它?从上面的第二个链接中,您可以看到
fig.show
print(fig)
将显示有关图形结构的一些细节。但肯定不是全部。下面的代码段将生成以下绘图:

绘图:

代码: 运行
fig.show
将以dict的形式部分显示图形的结构:

<bound method BaseFigure.show of Figure({
    'data': [{'hovertemplate': 'year=%{x}<br>lifeExp=%{y}<extra></extra>',
              'legendgroup': '',
              'line': {'color': '#636efa', 'dash': 'solid'},
              'mode': 'lines',
              'name': '',
              'orientation': 'v',
              'showlegend': False,
              'type': 'scatter',
              'x': array([1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, 2002, 2007],
                         dtype=int64),
              'xaxis': 'x',
              'y': array([68.75 , 69.96 , 71.3  , 72.13 , 72.88 , 74.21 , 75.76 , 76.86 , 77.95 ,
                          78.61 , 79.77 , 80.653]),
              'yaxis': 'y'}],
    'layout': {'legend': {'tracegroupgap': 0},
               'template': '...',
               'title': {'text': 'Life expectancy in Canada'},
               'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'year'}},
               'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title': {'text': 'lifeExp'}}}
})

从4.10版开始,plotly开发人员引入了他们所谈论的可怕的
fig.full\u figure\u for\u development()函数。在这里,您将看到:

fig.full\u figure\u for\u development()
函数将返回一个新的
go.figure
对象,并预先填充与您提供的值相同的值以及所有 Plotly.js计算的默认值,用于了解更多信息 关于哪些属性控制你身材的每个细节,以及你如何 您可以自定义它们。此函数名为“for development”,因为 没有必要用它来生成数字,但它确实可以 方便您在了解如何构建图形的同时探索图形

因此,以问题中的示例为基础,以下代码段将生成大约180行的输出,其中包含大量其他细节,这部分关于图形布局:

'margin': {'autoexpand': True, 'b': 80, 'l': 80, 'pad': 0, 'r': 80, 't': 100},
'modebar': {'activecolor': 'rgba(68, 68, 68, 0.7)',
           'bgcolor': 'rgba(255, 255, 255, 0.5)',
           'color': 'rgba(68, 68, 68, 0.3)',
           'orientation': 'h'},
'newshape': {'drawdirection': 'diagonal',
            'fillcolor': 'rgba(0,0,0,0)',
            'fillrule': 'evenodd',
            'layer': 'above',
            'line': {'color': '#444', 'dash': 'solid', 'width': 4},
            'opacity': 1},
'paper_bgcolor': 'white',
'plot_bgcolor': '#E5ECF6',
'separators': '.,',
'showlegend': False,
'spikedistance': 20,
在那里,您还可以看到绘图的背景色为
“plot\u bgcolor”:“E5ECF6”
。您可能知道,您可以使用设置背景颜色,例如使用
fig.update\u layout(plot\u bgcolor='grey')
。但现在你也知道如何得到它了:

# In:
fig.layout.plot_bgcolor

# Out:
'#E5ECF6'
在知道如何做到这一点的过程中,您知道如何获取和设置plotly地物的几乎任何属性。并且,无论您是使用
plotly.graph\u objects
还是
plotly.express

# In:
fig.layout.plot_bgcolor

# Out:
'#E5ECF6'