MCPcopy Create free account
hub / github.com/TRIQS/triqs / plot

Function plot

python/triqs/stat/histogram.py:31–79  ·  view source on GitHub ↗

r""" Plot protocol for Histogram objects. Builds the keyword-argument dictionary consumed by :func:`triqs.plot.protocol.plot_protocol_apply`. Registered via ``plot_function_table[Histogram] = plot`` in :mod:`triqs.stat`, so ``triqs.plot.oplot(h)`` dispatches here for a Histogram

(self, optional_dict)

Source from the content-addressed store, hash-verified

29
30# Only the plot function, everything else is wrrapped from c++
31def plot(self, optional_dict):
32 r"""
33 Plot protocol for Histogram objects.
34
35 Builds the keyword-argument dictionary consumed by
36 :func:`triqs.plot.protocol.plot_protocol_apply`. Registered via
37 ``plot_function_table[Histogram] = plot`` in :mod:`triqs.stat`,
38 so ``triqs.plot.oplot(h)`` dispatches here for a Histogram ``h``.
39 Bin abscissae come from :attr:`Histogram.limits` and ``len(h)``;
40 ordinates from :attr:`Histogram.data` (raw counts -- pass
41 ``pdf(h)`` or ``cdf(h)`` to plot normalised distributions).
42
43 Recognised keys in ``optional_dict`` are listed below; any
44 additional keys are forwarded unchanged to the matplotlib call.
45
46 Parameters
47 ----------
48 type : str, optional
49 Drawing mode for the histogram. ``'XY'`` (default) plots bin
50 centres as a line; ``'bar'`` draws bars centred on the bin
51 centres.
52 width : float, optional
53 Bar width used when ``type='bar'``. Defaults to the bin
54 spacing ``(b - a) / (n_bins - 1)``.
55
56 Returns
57 -------
58 plot_data : list of dict
59 Single-element list whose dictionary holds the keyword
60 arguments forwarded by ``triqs.plot.oplot``: ``xdata``,
61 ``ydata``, ``label``, ``plot_function``, and (in bar mode)
62 ``width``.
63 """
64
65 plot_type = optional_dict.pop('type','XY')
66 bin_centres = np.linspace(self.limits[0],self.limits[1],len(self))
67 bin_width = optional_dict.pop('width', (self.limits[1] - self.limits[0])/(len(self) - 1))
68 bin_edges = bin_centres - ((bin_width/2) if plot_type=='bar' else 0)
69
70 default_dict = {'xdata': bin_edges,
71 'ydata': self.data,
72 'label': 'Histogram',
73 'plot_function': 'plot' if plot_type=="XY" else 'bar'
74 }
75 if plot_type=='bar' and not 'width' in optional_dict:
76 default_dict['width'] = bin_width
77 default_dict.update(optional_dict)
78
79 return [default_dict]

Callers

nothing calls this directly

Calls 1

updateMethod · 0.80

Tested by

no test coverage detected