Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Good afternoon all,
I'm very new to scripting visuals in Power BI using Python and I have run into a bit of a snag.
I am attempting to script a 3D bar chart that is interactive using Matplotlib Widgets. For this particular visual I would just like to be able to rotate it on all three axes. Unfortunately I can't get the widgets to work correctly and and I'm wondering if they are able to be used in Power BI. Below is a snippet of the code. When I don't use %matplotlib widget, the visual is generated correctly (as shown). Can anyone point me in the right direction?
# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:
# dataset = pandas.DataFrame(Year, Quarter, Month, Day)
# dataset = dataset.drop_duplicates()
# Paste or type your script code here:
# creating 3d bar plot using matplotlib
# in python
# to interacte with plot
%matplotlib widget
# importing required libraries
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
# creating random dataset
xs = [2, 3, 4, 5, 1, 6, 2, 1, 7, 2]
ys = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
zs = np.zeros(10)
dx = np.ones(10)
dy = np.ones(10)
dz = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# creating figure
figg = plt.figure()
ax = figg.add_subplot(111, projection='3d')
# creating the plot
plot_geeks = ax.bar3d(xs, ys, zs, dx,
dy, dz, color='green')
# setting title and labels
ax.set_title("3D bar plot")
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
ax.set_zlabel('z-axis')
# displaying the plot
plt.show()
Solved! Go to Solution.
Hi @Ncf5031,
I haven't used the library but I imagine that Matplotlib Widgets require an interactive canvas of some kind for this operation to occur. Python visuals are rendered by Power BI as a static image and only update from external events on the report page, and not from any events within the visual. If the visual doesn't display when enabled, it's likely that Matplotlib Widgets is causing rendering issues when Power BI attempts to return the image output to the visual.
Regards,
Daniel
Proud to be a Super User!
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
Hi @Ncf5031,
I haven't used the library but I imagine that Matplotlib Widgets require an interactive canvas of some kind for this operation to occur. Python visuals are rendered by Power BI as a static image and only update from external events on the report page, and not from any events within the visual. If the visual doesn't display when enabled, it's likely that Matplotlib Widgets is causing rendering issues when Power BI attempts to return the image output to the visual.
Regards,
Daniel
Proud to be a Super User!
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
@dm-p thank you for the answer, that makes complete sense. I appreciate you taking the time to explain this to me.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
6 | |
4 | |
2 | |
2 |
User | Count |
---|---|
4 | |
3 | |
3 | |
3 | |
3 |