Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Ncf5031
Advocate I
Advocate I

Matplotlib Widgets

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()

 

Python.png

1 ACCEPTED SOLUTION
dm-p
Super User
Super User

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

2 REPLIES 2
dm-p
Super User
Super User

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


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. 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.