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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
J_Castro
Frequent Visitor

Python visual on the Service doesn't render as in PBI Desktop

I'm trying to post a 3D scatter plot on the Service but I am getting the error. If I remove the ax formatting I get it, but it's not what I expect.

Does anyone know any alternative?

Below is the error message, a screenshot of how it beautifully looks on Desktop and what I could get on the Service.

To replicate it I am providing the M code to generate the data and the Python viz (ax formatting lines commented with #).

 

Script Runtime Error

fig.add_axes(ax)

[S-ecccd5b8-55de-460e-b32a-be84188e4e5c]NotImplementedError: It is not currently possible to manually set the aspect on 3D axes

Please try again later or contact support. If you contact support, please provide these details.

On DesktopOn Desktop On Service, removing the ax formattingOn Service, removing the ax formatting

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lZTBasMwDIZfJXiXFEqQbSm1r2kvg1IGG3Rb6KHQwQppC2XvT52uW5eAZ/8Ho0T580myZbWtWuy3h6J8XE3UVK33u6/Pn5enbns8fuyK9UtRLpvn3vUa1ltY72HNT93pXGm1mbZKKDi8rmbByIxcML2HKro9PRD5pnZ3sZPrNzHeBsMykrvGEVFMLoTJMfpdLFm5QHJNoB7kG5BvQL5N8odtMN76//vAgtkwWC2DfAH5kuTXXElfqDf8e7o3xlXva27i+u/TBfQg34J8m+QPu0GPL+64HYZ4BtNhsFwB+QLy/zZIVjqYXhP6AxrBoBFMOkJ8vmVcGIsmZNGSGY3AaARJR4jP9IwhZFJbGp/oOXKMzjH65gI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Z", type number}, {"Y", type number}, {"X", type number}, {"Planned WT (LBS)", type number}, {"Width (IN)", type number}, {"Diam (IN)", type number}})
in
    #"Changed Type"

 

 

# 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(Diam (IN), X, Y, Z, Width (IN), Railcar)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:

df = dataset

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.path import Path
import numpy as np

def plot_cylinder(x, y, z, r, h, cylinder_color):

    if y == 0:
        y = r
    elif y > 0:
        y = y + r + 5

    
    def data_for_cylinder_along_z(center_x,center_y,radius,height_z):
        z = np.linspace(0, height_z, 50)
        theta = np.linspace(0, 2*np.pi, 50)
        theta_grid, z_grid=np.meshgrid(theta, z + h)
        x_grid = radius*np.cos(theta_grid) + center_x
        y_grid = radius*np.sin(theta_grid) + center_y
        return x_grid,y_grid,z_grid
    
    Xc,Yc,Zc = data_for_cylinder_along_z(x+r, y, r, z)
    ax.plot_surface(Xc,Yc,Zc, 
                    alpha=0.95,
                    color= cylinder_color,
                    #cmap='Set1',
                    rstride=3, 
                    cstride=3
                   )


fig = plt.figure(figsize=(7,4))
ax = Axes3D(fig)
fig.add_axes(ax)

#ax.set_xlim3d(0, 600)
#ax.set_ylim3d(0, 108)
#ax.set_zlim3d(0, 154)

#ax.set_zticks(np.arange(0, 154, step=10))
#ax.zaxis.set_tick_params(labelsize=5)

#ax.set_yticks(np.arange(0, 108, step=25))
#ax.yaxis.set_tick_params(labelsize=5)

#ax.set_xticks(np.arange(0, 600, step=25))
#ax.xaxis.set_tick_params(labelsize=5)

#ax.set_aspect('equal', adjustable='box')

for i, row in df.iterrows():
    
    plot_cylinder(
        int(row['X']), 
        int(row['Z']),
        int(row['Width (IN)']),
        int(row['Diam (IN)']) / 2,
        int(row['Y']),
        row['Color.1']
    )

ax.view_init(30, -40)

plt.show()

 

7 REPLIES 7
J_Castro
Frequent Visitor

I can see it in the workspace. It just doesn't render when I use the ax formatting properties and methods 😞

lbendlin_0-1697498912371.png

Setting it to "auto"  i get this in the desktop

lbendlin_0-1697499177659.png

 

and this in the service

lbendlin_1-1697499197331.png

 

It looks a little better, but not quite what I wanted/expected.

Am I right in affirming there is no way yet of keeping the real proportions among the axes?

Don't know about that but there is certainly some version mismatch and/or deprecation involved.

lbendlin
Super User
Super User

Are you running the Personal Gateway on your PC?

 

BTW, your sample data gives me this:

lbendlin_0-1697411837459.png

 

Hi @lbendlin ,

I just published to My Workspace to test. No gateway setup yet.

I would like to have the output like this, in a rectangular aspect ratio, not a square.

Please try uncommenting the lines in the Python viz code to see if you get the same error I got on the Service.

3D Scatter in PBI Desktop.png

 

My understanding is that you need a personal gateway set up, and running, to see these visuals in the workspace.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.