cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
barakb32
Advocate I
Advocate I

Python padding

Hi,

 

I used the Python visual to embed a scatter in my report.

I would like the scatter to fill the screen. I have 2 issues with that:

 

1. The python visual comes with a lot of padding. I have huge white space between the border of the visual and the axis of the scatter

2. The scatter comes out square. I don't know how to make its width larger than its height, even if the visual wrapping it is more wide than tall

 

Can this be solved in for Python visual or for R visual?

 

Thanks,

Barak

1 ACCEPTED SOLUTION

OK,

 

Solved it with the size and aspect parameters.

 

Barak

View solution in original post

6 REPLIES 6
v-yuta-msft
Community Support
Community Support

@barakb32 ,

 

The padding size should be decided by the python code you are using. Could you share some part of the python code for further analysis?

 

Community Support Team _ Jimmy Tao

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

This is the code as it appears in Power BI:

 

 

import matplotlib.pyplot as plt
import pandas as pd 
import seaborn as sns
sns.set_palette("pastel")
#print (sns.get_dataset_names())
df = pd.DataFrame(dict(x=dataset['Probability01'], y=dataset['Impact110']))
#plt.scatter(x=dataset['Probability01'],y=dataset['Impact110'],s=dataset['Booking']/10000)
lm=sns.lmplot(x='Probability01',y='Impact110',data=dataset,hue='Proj_Type',scatter_kws={'s': dataset['Booking']/10000})
#axes=lm.axes
#axes[0,0].set_ylim(-1,)
#axes[0,1].set_xlim(0,)
plt.xlim(-0.1,1.1)
plt.ylim(-1,11)
for i, txt in enumerate(dataset["Project Name"]):
plt.annotate(txt, (df.x.iat[i],df.y.iat[i]),fontsize=15)
plt.show()

 

 

and this is how it appears in spyder:

 

# Prolog - Auto Generated #
import os, matplotlib.pyplot, uuid, pandas
os.chdir(u'C:/Users/barakb/PythonEditorWrapper_2dac1e75-9317-429d-ac0d-8f5d9b7f0e89')
dataset = pandas.read_csv('input_df_55fe400c-1be7-4c16-b559-82ca736d13b9.csv')
matplotlib.pyplot.figure(figsize=(10,10))
matplotlib.pyplot.show = lambda args=None,kw=None: matplotlib.pyplot.savefig(str(uuid.uuid1()))
# Original Script. Please update your script content here and once completed copy below section back to the original editing window #
import matplotlib.pyplot as plt
import pandas as pd 
import seaborn as sns
sns.set_palette("pastel")
#print (sns.get_dataset_names())
df = pd.DataFrame(dict(x=dataset['Probability01'], y=dataset['Impact110']))
#plt.scatter(x=dataset['Probability01'],y=dataset['Impact110'],s=dataset['Booking']/10000)
lm=sns.lmplot(x='Probability01',y='Impact110',data=dataset,hue='Type',scatter_kws={'s': dataset['Booking']/10000})
#axes=lm.axes
#axes[0,0].set_ylim(-1,)
#axes[0,1].set_xlim(0,)
plt.xlim(-0.1,1.1)
plt.ylim(-1,11)
for i, txt in enumerate(dataset["Project Name"]):
plt.annotate(txt, (df.x.iat[i],df.y.iat[i]),fontsize=15)
plt.show()
 

# Epilog - Auto Generated #
os.chdir(u'C:/Users/barakb/PythonEditorWrapper_2dac1e75-9317-429d-ac0d-8f5d9b7f0e89')

 

BTW1: I don't think that's a Python padding, since I changed the visual background to transparent and put a rectangle behind it.

While the plot area hides the rectangle, the padding/whitespace doesn't hide it.

 

BTW2: There is not much padding when the visual is small. The padding comes intoplace when I enlarge the visual to fill the screen.

 

Barak 

OK,

 

Solved it with the size and aspect parameters.

 

Barak

View solution in original post

Hi Barak,

Can you explain better what you mean by "Solved it with the size and aspect parameters."? Where are those parameters? Did you change them in powerbi or in the code in python?


@barakb32 wrote:

OK,

 

Solved it with the size and aspect parameters.

 

Barak


 

Hi @t-vicarm ,

 

These are parameters of the python command seaborn.lmplot.

 

The adjusted command looks like this:

 

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

 

Barak

Hi

 

Just to add more information, for matplotlib is possible to control the padding using the tight_layout() options.

 

matplotlib.pyplot.tight_layout()
matplotlib.pyplot.show()

In my case, the axis labels where shown just partially, and aplying this option was possible to control the complete figure size and pad.

 

Alexis

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors