Forum Discussion
Python padding
- 7 years ago
OK,
Solved it with the size and aspect parameters.
Barak
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
- t-vicarm7 years agoMicrosoft Employee
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
- barakb327 years agoAdvocate I
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
- aechague6 years agoAdvocate II
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