问题描述
我正在查看以下教程的饼图子图"部分(页面上的最后一个)https://plot.ly/python/pie-charts/.
I am looking at the 'Pie Chart Subplots' section (last one on page) of the following tutorial https://plot.ly/python/pie-charts/.
在一次绘制多个图形时,我不知道如何理解域变量.例如:
I cant figure out how to understand the domain variable when it comes to plotting multiple graphs at once. For instance:
{
'labels': ['1st', '2nd', '3rd', '4th', '5th'],
'values': [38, 27, 18, 10, 7],
'type': 'pie',
'name': 'Starry Night',
'marker': {'colors': ['rgb(56, 75, 126)',
'rgb(18, 36, 37)',
'rgb(34, 53, 101)',
'rgb(36, 55, 57)',
'rgb(6, 4, 4)']},
'domain': {'x': [0, .48],
'y': [0, .49]},
'hoverinfo':'label+percent+name',
'textinfo':'none'
},
将在左下角坐标绘制一个饼图.
will plot a pie chart in the bottom left coordinates.
有人可以解释域变量(及其 x 和 y 分量)在 plotly 中的实际工作原理吗?
Can someone explain how the domain variable (and its x and y components) works in practice in plotly?
推荐答案
我们只使用Javascript,因为它可以在这里执行.域属性在 Python 和 Javascript 中是相同的.
Let's just use Javascript because it can be executed here. The domain attribute is identical in Python and Javascript.
来自文档:
域
x
(数组)
默认值:[0, 1]
设置此饼图的水平域(在绘图部分中).每个对象都有下面列出的一个或多个键.
Sets the horizontal domain of this pie trace (in plot fraction). Each object has one or more of the keys listed below.
数组的第一个成员是开始位置,第二个成员是结束位置.
The first member of the array is the start position and the 2nd member is the end position.
对于x
0
表示一直向左,1
表示一直向右.
For x
0
means all the way to the left and 1
is all the way to right.
对于 y
0
是顶部,1
是底部.
For y
0
is top and 1
is bottom.
例如左上象限是 x = [0, 0.5]
和 y = [0, 0.5]
e.g. the upper left quadrant would be x = [0, 0.5]
and y = [0, 0.5]
如果您有多个地块,例如在下面的示例中,有两个 div
,每个有 4 个绘图,每个绘图的域指定它占用的空间.在第一个示例中,每个地块获得四分之一的可用空间(即 x 和 y 设置为 0 到 0.5 和 0.5 到 1).
If you have multiple plots, e.g. in the example below there are two div
s with 4 plots each, the domain of each plot specifies which space is occupied by it. In the first example each plot gets a quarter of the available space (i.e. x and y are set to 0 to 0.5 resp. 0.5 to 1).
在第二个示例中,最后一个图的 domain
与其他域重叠(0.25 到 0.75).
In the second example the domain
of the last plot overlaps with the other domains (0.25 to 0.75).
在第三个示例中,最后一个图的 domain
更大,并与其余部分重叠(0 到 0.75).
In the third example the domain
of the last plot is bigger and overlaps with the rest (0 to 0.75).
简而言之,domain
只是指定子图占用总绘图区域的哪个空间.
In short, domain
just specifies which space of the total plot area is occupied by the subplot.
var allValues = [
[50, 30, 20],
[45, 30, 25],
[55, 25, 20],
[50, 15, 35]
];
var data = [{
values: allValues[0],
type: 'pie',
domain: {
x: [0, .5],
y: [0, .5]
},
}, {
values: allValues[1],
type: 'pie',
domain: {
x: [0.5, 1],
y: [0, .5]
}
}, {
values: allValues[2],
type: 'pie',
domain: {
x: [0, .5],
y: [.5, 1]
}
}, {
values: allValues[3],
type: 'pie',
domain: {
x: [0.5, 1],
y: [0.5, 1]
},
}];
Plotly.newPlot('myDiv', data);
data[3].domain.x = [0.25, 0.75];
data[3].domain.y = [0.25, 0.75];
Plotly.newPlot('myDiv2', data);
data[3].domain.x = [0.0, 0.75];
data[3].domain.y = [0.0, 0.75];
Plotly.newPlot('myDiv3', data);
<div id='myDiv'></div>
<div id='myDiv2'></div>
<div id='myDiv3'></div>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
这篇关于Plotly 域变量解释(多图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!