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
opl12
Regular Visitor

Seasonality Graph with Average Historical, Max, Min - Converter Graph from Python to just Power BI

Good morning,

Can anyone tell me how to replicate this seasonality graph in Power BI?

 

On the "X" axis I have the months and as a measure I have:

  • Historical average of the last 5 years.
  • Maximum average of these 5 years.
  • Minimum average of these 5 years.
  • Result of the previous year.
  • Current year result.

I could only do it in Python, but because the base is quite large, the graph takes an average of 5 to 10 seconds to appear.
If you have a solution via Power BI graphics, it would be much better.

I'll share here the code I used to do it in Python (if maybe there's something that can be done to optimize the code)

Thanks in advance for your help

 

DouglasRocha_0-1685452518359.png

Code in Python:

 

 

 

import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import make_interp_spline


plt.rcParams["figure.figsize"]=(30,10)


font = {
        'family' : 'normal', # dict com dados de fontes
        'weight' : 'bold',
        'size'   : 15
       }

matplotlib.rc('font', **font)

plt.style.use("bmh")  #("seaborn") ("ggplot") ("Solarize_Light2") ("fivethirtyeight") ("dark_background")


ax = plt.gca()
dataset.plot(kind='line', x='MONTH_NAME', y='AVERAGE_5_YEARS', color='k', ax=ax, linestyle='dotted', label='Media', linewidth=3.5)
dataset.plot(kind='line', x='MONTH_NAME', y='VALUE_LAST_YEAR', color='red', ax=ax, linestyle='dotted', label='Ano Anterior', linewidth=3.5)
dataset.plot(kind='line', x='MONTH_NAME', y='VALUE_YEAR_TODAY', color='mediumblue', ax=ax,  marker='o', label='Ano Atual', linewidth=3.5)
dataset.plot(kind='line', x='MONTH_NAME', y='MAX_VALUE_5_YEARS', color='grey', ax=ax, label='Max')
dataset.plot(kind='line', x='MONTH_NAME', y='MIN_VALUE_5_YEARS', color='grey', ax=ax, label='Min')

plt.legend(prop={'size':10}, loc=2, facecolor='gray')

x = dataset['MONTH_NAME']
y = dataset['MAX_VALUE_5_YEARS']
y1 = dataset['MIN_VALUE_5_YEARS']

plt.fill_between(x, y, y1,  facecolor='grey') #hatch='\\\\',

ax.axes.xaxis.set_visible(True)
ax.axes.yaxis.set_visible(True)

ax.tick_params(axis='x', colors='darkgray')
ax.tick_params(axis='y', colors='darkgray')

plt.xlabel("", labelpad=7)
plt.xlim(left=0)
plt.grid(color = 'darkgray', linestyle = '--', linewidth = 0.5)


plt.savefig("grafico-background-05.png", dpi=150, transparent='True')

plt.show()

 

 

 

 

 

1 ACCEPTED SOLUTION
opl12
Regular Visitor

I solved it by placing one graphic on top of the other

first an area chart with maximum and minimum, and then another chart with the other measures

View solution in original post

1 REPLY 1
opl12
Regular Visitor

I solved it by placing one graphic on top of the other

first an area chart with maximum and minimum, and then another chart with the other measures

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.