Issue
I have the following code that plots 2 Pie charts and places them on top of each other. I want to make the total radius of the inner Pie chart smaller so that there is some gap between the two donuts, and the labels for the inner donut appear centered and not hidden behind the outer one.
I just want to change the relative size of the two traces, and not the entire figure, so fig.update_layout()
does not work for me.
import plotly.graph_objs as go
labels_1 = ['Server 1','Server 2','Server 3','Server 4']
values_1 = [4500, 2500, 1053, 500]
trace_1 = go.Pie(labels=labels_1, values=values_1, hole=.7)
labels_2 = ['Client 1','Client 2']
values_2 = [4500, 2184]
trace_2 = go.Pie(labels=labels_2, values=values_2, hole=.3)
fig = go.Figure(data=[trace_2, trace_1])
fig.show()
Currently, my nested pychart looks like this:
Solution
The pie trace markers don't have a direct width
or size
attribute. So it seems to me that you'll have to handle this case through a combination of hole
(like you're already doing) and domain
like this:
fig.data[0].domain = {'x': [0, 1], 'y': [0.25, 0.75]}
Plot
complete code:
import plotly.graph_objs as go
labels_1 = ['Server 1','Server 2','Server 3','Server 4']
values_1 = [4500, 2500, 1053, 500]
trace_1 = go.Pie(labels=labels_1, values=values_1, hole=.6)
labels_2 = ['Client 1','Client 2']
values_2 = [4500, 2184]
trace_2 = go.Pie(labels=labels_2, values=values_2, hole=.3)
fig = go.Figure(data=[trace_2, trace_1])
f = fig.full_figure_for_development(warn=False)
fig.update_layout(width = 1400)
fig.data[0].domain = {'x': [0, 1], 'y': [0.25, 0.75]}
fig.show()
Answered By - vestland
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.