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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
bobbob123
Helper III
Helper III

Remove outside padding on Python Visual

Hi, 

 

I have created a visual using my python script. I want to learn how to remove all that extra padding between the graph and the visual boundary so that it doesn't take up too much space.

 

 

My Python code is:

 

 

import seaborn as sns 
import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(30,18))
for label in (ax.get_xticklabels() + ax.get_yticklabels()):
	label.set_fontsize(30)
plt.xlabel('Year', fontsize=30)
plt.ylabel('Mark', fontsize=30)
ax = sns.swarmplot(x='Year',y='Mark',data=dataset,palette="Set1",size=10)
plt.xticks(rotation=0)
plt.show()

 

 InkedScreenshot 2022-03-20 200113.jpg

1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @bobbob123 

 

solutio1:
plt.tight_layout() takes three arguments. You want to set them all to 0. Like

plt.tight_layout(pad=0, w_pad=0, h_pad=0).

solution2:

Solved it with the size and aspect parameters. These are parameters of the python command seaborn.lmplot.
Like
lm=sns.lmplot(x='Probability01',y='Impact110',data=dataset,hue='Proj_Type',fit_reg=False,size=10,aspect=1.5,scatter_kws={'s': dataset['Booking']/2000})

Refer:
https://stackoverflow.com/questions/56127743/eliminate-white-space-margins-from-matplotlib-graph-in-...

https://community.powerbi.com/t5/Desktop/Python-padding/m-p/644031

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-angzheng-msft
Community Support
Community Support

Hi, @bobbob123 

 

solutio1:
plt.tight_layout() takes three arguments. You want to set them all to 0. Like

plt.tight_layout(pad=0, w_pad=0, h_pad=0).

solution2:

Solved it with the size and aspect parameters. These are parameters of the python command seaborn.lmplot.
Like
lm=sns.lmplot(x='Probability01',y='Impact110',data=dataset,hue='Proj_Type',fit_reg=False,size=10,aspect=1.5,scatter_kws={'s': dataset['Booking']/2000})

Refer:
https://stackoverflow.com/questions/56127743/eliminate-white-space-margins-from-matplotlib-graph-in-...

https://community.powerbi.com/t5/Desktop/Python-padding/m-p/644031

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.