A shiny distribution curve to lend credibility to guesstimates. This object is used to generate two separarate distributions: 1) a main distribution curve with pdf to analyze Risk distribution, and 2) a miniature distribution which covers the spread of an individual input argument.
| 12 | |
| 13 | |
| 14 | class FairDistributionCurve(FairBaseCurve): |
| 15 | """A shiny distribution curve to lend credibility to guesstimates. |
| 16 | |
| 17 | This object is used to generate two separarate distributions: 1) a main |
| 18 | distribution curve with pdf to analyze Risk distribution, and 2) a |
| 19 | miniature distribution which covers the spread of an individual |
| 20 | input argument. |
| 21 | |
| 22 | Parameters |
| 23 | ---------- |
| 24 | model_or_iterable : FairModel, FairMetaModel, or list of |
| 25 | FairModels/FairMetaModels |
| 26 | |
| 27 | Examples |
| 28 | -------- |
| 29 | >>> m = pyfair.model.FairModel.from_json('model_1.json') |
| 30 | >>> dc = pyfair.report.FairDistributionCurve(m) |
| 31 | |
| 32 | """ |
| 33 | def __init__(self, model_or_iterable): |
| 34 | self._input = self._input_check(model_or_iterable) |
| 35 | |
| 36 | def generate_icon(self, model_name, target): |
| 37 | """Generate a minimalist histogram for for a given model/parameter |
| 38 | |
| 39 | Parameters |
| 40 | ---------- |
| 41 | model_name : str |
| 42 | The name of the model for which to generate the histogram |
| 43 | |
| 44 | target : str |
| 45 | The name of the parameter for which to generate the histogram |
| 46 | |
| 47 | Returns |
| 48 | ------- |
| 49 | (matplotlib.figure, matplotlib.ax) |
| 50 | A tuple containing the figure and axis generated |
| 51 | |
| 52 | Examples |
| 53 | -------- |
| 54 | >>> m = pyfair.model.FairModel.from_json('model_1.json') |
| 55 | >>> dc = pyfair.report.FairDistributionCurve(m) |
| 56 | >>> fig, ax = dc.generate_icon() |
| 57 | |
| 58 | """ |
| 59 | model = self._input[model_name] |
| 60 | data = model.export_results().loc[:, target] |
| 61 | # Set up ax and params |
| 62 | fig, ax = plt.subplots(figsize=(6, 1)) |
| 63 | ax.set_xlim(0, data.max()) |
| 64 | # Set spines and axis invisible |
| 65 | for spine in ['left', 'right', 'top', 'bottom']: |
| 66 | ax.spines[spine].set_visible(False) |
| 67 | plt.tick_params(bottom=False) |
| 68 | ax.yaxis.set_visible(False) |
| 69 | # Tweak ticks based on content |
| 70 | if data.max() <= 1: |
| 71 | ax.axes.xaxis.set_major_formatter(StrMethodFormatter('{x:,.2f}')) |
no outgoing calls