Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

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

 

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

 

 

 

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    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

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    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