1

I want to learn how to change the look of fitter's output plot. Here is the example

import fitter as ft
import matplotlib.pyplot as mp
from numpy.random import lognormal

data = lognormal(size=1000)

d = ['expon','weibull_min','pareto','gengamma','lognorm']
f = ft.Fitter( data, distributions=d, bins=50)
f.fit()
f.summary()

output:

enter image description here

I need to change the colors (both the histogram and the lines) and add some edge lines to the bins. I tried some matplotlib codes to change the grid style and remove some of the borders (below). But that's it.. I cant change the histogram and plot lines:

f.summary(lw=1.3)

mp.gca().set_axisbelow(True)
mp.gca().spines['right'].set_visible(False)
mp.gca().spines['top'].set_visible(False)

mp.gca().grid(color='#cccccccc', linestyle=':', 
              linewidth=0.7, which='both')

mp.show()
Erdem Şen
  • 97
  • 1
  • 10
  • 2
    (Side note): Gah, `fitter` uses `pylab` under the hood... that's terrible. – BigBen Aug 22 '23 at 19:05
  • 2
    The official `matplotlib` documentation states not to use `pylab`: [Which is the recommended way to plot: matplotlib or pylab?](https://stackoverflow.com/a/51011921/7758804). You should just directly use [`scipy.stats`](https://docs.scipy.org/doc/scipy/reference/stats.html), `pandas`, and `matplotlib` – Trenton McKinney Aug 22 '23 at 19:22
  • i don't understand the negative vote... is something wrong with the question? – Erdem Şen Aug 22 '23 at 19:26
  • [`def summary`](https://github.com/cokelaer/fitter/blob/main/src/fitter/fitter.py#L441) does not **appear** to return the plot object, so you may be SOL. – Trenton McKinney Aug 22 '23 at 19:43

1 Answers1

2

I found an indirect solution. As mentioned in the comments above fitter uses pylab and it makes styling hard. But with help of seaborn and cycler it still can be done:


import seaborn as sns
from cycler import cycler

sns.set_theme()
sns.set_style(rc = {'axes.facecolor': 'w'})


mp.rc('lines', linewidth=1.5, linestyle='-')
mp.rcParams['axes.prop_cycle'] = cycler(color=['#20202077',
                                               '#029020dd',
                                               '#FF8C00dd',
                                               '#ff00ffcc',
                                               '#2020ffdd']
                                               # alpha=[1, 1, 1, 1, .7]
                                          )

f.summary(plot=True, lw=2)

mp.gca().set_axisbelow(True)
mp.gca().grid(color='#cccccccc', linestyle=':', 
              linewidth=1.5, which='both')

mp.show()

output:

enter image description here

Erdem Şen
  • 97
  • 1
  • 10