Forum Discussion
Use Plotly with Python Script in Power BI
- 7 years ago
Hi Anonymous ,
I'm afraid that Plotly is not supported in Power BI currenly.
Based on the blog, only the following Python packages (non-Intel MKL) are currently supported for use in your Power BI reports.
- matplotlib
- numpy
- pandas
- scikit-learn
- scipy
- seaborn
- statsmodels
In addition, you could refer to this similar thread which should make sense.
Best Regards,
Cherry
Hi there!
I recently tried to create a gauge chart with dial in Power BI using python script. There are 2 variants which I attempted:
1. Using Matplotlib pyplot
2. Using plotly
The one using Matplotlib is actually a polar chart with it's bottom half invisible. To develop a gauge chart is more of a workaround but it's implementation in Power BI though is pretty straightforward and more compatible in terms of display. No workarounds needed! Simply create the custom visual you need and show it in the BI report.
On the other hand, the variant using Plotly has better & clear features as there is a builtin functionality meant for Gauge charts. While it's super simple to create the kind of gauge chart you need, displaying it inside the python visual in PBI is a hassle! You are constantly bombarded with the following error:
To solve this, I had to convert the plot to an image using kaleido.
fig.write_image('gauge_chart.png', engine='kaleido')
Then I loaded the image into Matplotlib with this:
# Read the saved image and display it using matplotlib
img = Image.open('gauge_chart.png')
plt.imshow(img)
plt.axis('off') # Hide the axes
plt.show()
And voila! The plot will now appear in the python visual.
Though the flexibility to develop better gauge charts is present in Plotly, it's implementation is quite a puzzle! And this needs more dependencies unlike the Matplotlib version!
Had to use all of these:
import plotly.graph_objects as go
import pandas as pd
import plotly.io as pio
from PIL import Image
import matplotlib.pyplot as plt
Hope this helps someone!
Thanks!