Я пытаюсь визуализировать поток беженцев с помощью диаграммы Санки с использованием сюжета lib, но все, что я получаю, это пустая диаграмма.
Я пытался следовать https://www.kaggle.com/meetnaren/past-and-current-job-titles-of-data-professionals/ и https://plot.ly/~alishobeiri/1257.embed, но это не сработало.
import plotly.plotly as py
import plotly
import matplotlib.pyplot as plt
countries = ['Australia', 'Austria', 'Belgium', 'Canada', 'China, Hong Kong SAR', 'Denmark', 'France', 'Germany', 'Greece', 'Italy', 'Luxembourg', 'Morocco', 'Netherlands', 'Norway', 'Spain', 'Sweden', 'Switzerland', 'Tunisia', 'Turkey', 'United Kingdom', 'United States of America']
origins = ['Various/Unknown', 'Various/Unknown', 'Various/Unknown', Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown', 'Various/Unknown']
values = [180000, 282000, 55000, 168511, 30000, 2000, 290000, 265000, 18000, 26500, 1800, 3000, 14200, 2500, 2000, 44000, 10000, 2000, 2700, 208000, 350000]
colors = ['#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46', '#262C46']
plotly.offline.init_notebook_mode()
data_trace = dict(
type='sankey',
domain = dict(
x = [0,1],
y = [0,1]
),
orientation = "h",
valueformat = ".0f",
node = dict(
pad = 10,
thickness = 30,
line = dict(
color = "black",
width = 0
),
label = values,
color = colors
),
link = dict(
source = origins,
target = countries,
value = values,
color = colors
)
)
layout = dict(
title = "Refugee Flow",
height = 772,
font = dict(
size = 10
),
)
fig = dict(data=[data_trace], layout=layout)
plotly.offline.iplot(fig)
Ожидаемый график.
Фактический результат: Бланк