1import openturns as ot
2from matplotlib import pyplot as plt
3from openturns.viewer import View
4
5pdf_graph = ot.Graph('PDF graph', 'x', 'PDF', True, 'topright')
6cdf_graph = ot.Graph('CDF graph', 'x', 'CDF', True, 'bottomright')
7palette = ot.Drawable.BuildDefaultPalette(10)
8for i, v in enumerate([(2, 0.83), (4, 0.66), (20, 0.33)]):
9    r, p = v
10    distribution = ot.NegativeBinomial(r, p)
11    pdf_curve = distribution.drawPDF().getDrawable(0)
12    cdf_curve = distribution.drawCDF().getDrawable(0)
13    pdf_curve.setColor(palette[i])
14    cdf_curve.setColor(palette[i])
15    pdf_curve.setLegend('r,p={},{}'.format(r, p))
16    cdf_curve.setLegend('r,p={},{}'.format(r, p))
17    pdf_graph.add(pdf_curve)
18    cdf_graph.add(cdf_curve)
19fig = plt.figure(figsize=(10, 4))
20pdf_axis = fig.add_subplot(121)
21cdf_axis = fig.add_subplot(122)
22View(pdf_graph, figure=fig, axes=[pdf_axis], add_legend=True)
23View(cdf_graph, figure=fig, axes=[cdf_axis], add_legend=True)
24fig.suptitle('NegativeBinomial(r,p)')
25