Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eliminate white space margins from Matplotlib graph in Power BI Service

I have an issue with white space margins of matplotlib graphs when these are published on Power BI service.

I can successfully generate the graph with minimal whitespace margins on PBI Desktop (image 1).

Power BI 1

My code is:

import matplotlib.pyplot as plt 
import numpy as np
import pandas as pd 
from matplotlib.pyplot import figure
data = dataset
x = data['Time Period']
y = data['Data Metric 4'].rolling(13).mean()
y1 = data['Data Metric 4'].rolling(1).sum()

plt.plot(x,y,linewidth = 6.0, color = 'orange')
plt.plot(x,y1,linewidth = 3.0)

plt.xticks(x, rotation = '60',fontsize = '8')

plt.xlabel("Time Period")
plt.ylabel("Data Metric")
plt.tight_layout()
plt.show()

When publishing this graph on PBI Service(app.powerbi.com), I'll get the below result (image 2 attached). The red arrows show you the blank space. Ideally, I want to bring my graph in such a state like image 1.

Power BI 2

Can this somehow be fixed and how?

like image 777
makman Avatar asked Jan 20 '26 03:01

makman


1 Answers

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

like image 110
Juba Avatar answered Jan 22 '26 17:01

Juba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!