Reputation: 87
I have some code that works well in Jupyter notebook. However, when I create a Python visual in Power BI, it opens in a browser instead. To note, I saved the components of the visual (data, color, labels) into one dataframe in order to use it in Power BI.
On Power BI, the following error is shown:
No image was created. The Python Code created didn't result in creation of any visuals. Make sure your Python script results in a plot to the Python default device.
import pandas as pd
import matplotlib.pyplot as plt
import plotly.graph_objects as go
df = dataset[['source', 'target', 'Value', 'label_s', 'label_t', 'cond', 'x_s', 'x_t']].copy().dropna()
labels = dataset[['index', 'id', 'label', 'x', 'y']].copy().dropna()
colors = dataset[['colors']].copy().dropna()
x_scale = 1/7.5
y_scale = 1/10
link = dict(source=df.source, target=df.target, value=df.Value, color=colors.colors,
hovertemplate='%{value}')
node = dict(label=labels['label'], thickness=5, pad=50, color='gray',
x=labels['x']*x_scale,
y=labels['y']*y_scale)
fig = go.Figure(go.Sankey(link=link, node=node, arrangement='fixed'))
fig.show()
How can I display the Sankey diagram in Power BI using Python? Or is there a better way to do this?
Upvotes: 1
Views: 1359
Reputation: 87
For anyone's reference, I have yet to find an answer to this question. I ended up just displaying a static version of the graph by replacing fig.show()
with
fig.write_image('Image_Name.png')
I don't know where this image saves exactly, but it does result in a plot in the Power BI dashboard.
Upvotes: 4