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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Python Visual Automatic Scaling and Aspect Ratio Based on Visual Dimensions on Report Canvas

Hi,

 

is there a way to automatically scale python plots based on the dimensions of the visual in a repart? I know, I can scale python plots inside the visual manually...

 

#Setting up the base plot size
matplotlib.pyplot.tight_layout()
fig, ax = plt.subplots(figsize = (5,1.5))
 
... but I would preferably get rid of the magic numbers in the above code so that I can easily resuse plotting code across different visuals and get a consistent appearance without having to play with the scaling manually to get the dimensions right.
 
In other words: are there any variables passed to the python code that allow me to get information about the area in which the generated PNG is "placed" inside the python visual?
 
Cheers, AAB
1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

Based on your description, this does not seem to be possible in powerbi. Or you can provide a relevant screenshot and describe it, and I will try to give you as much helpful information as possible.


Looking forward to your reply.


Best Regards,
Henry

 

View solution in original post

2 REPLIES 2
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

Based on your description, this does not seem to be possible in powerbi. Or you can provide a relevant screenshot and describe it, and I will try to give you as much helpful information as possible.


Looking forward to your reply.


Best Regards,
Henry

 

Anonymous
Not applicable

Well, noone else has an idea how to pull this off, so I accept that solution 🙂

 

It would have been great if PowerBI provided some "hidden arguments" to the wrapping python function that executes the user code with basic information such as the above.

 

Also, I just ran the following code...

 

# 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(DataInfo)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:

import os
f = open('foo.txt','w')
sys.stdout = f
f.write('dir: ------------\n')
print(dir())
f.write('globals:---------\n')
print(globals())
f.write('locals: ---------\n')
print(locals())
f.write('-----------------')
f.close()
os.system("notepad.exe foo.txt")

 

... and I cannot see anything in the scope of the wrapper function that hints upon this functionality. 

 

I did not really expect it to do this but I am gald I asked; it is an MS product after all 😉

 

Cheers, Andy

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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