Skip to content

Commit 23887ee

Browse files
authored
Merge pull request #33 from VisualMelon/HistogramSeriesDocumentation
Add HistogramSeries documentation
2 parents f463d70 + 3e11b91 commit 23887ee

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed

models/series/HistogramSeries.png

14.7 KB
Loading

models/series/HistogramSeries.rst

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
===============
2+
HistogramSeries
3+
===============
4+
5+
.. note:: This section is under construction. Please contribute!
6+
7+
.. note:: The ``HistogramSeries`` is currently only available in a pre-release package
8+
9+
A ``HistogramSeries`` shows areas on a ``LinearAxis``.
10+
11+
Axes
12+
----
13+
14+
A vertical ``LinearAxis`` and a horizontal ``LinearAxis`` is required.
15+
16+
By default, the ``HistogramSeries`` will use the default horizontal and
17+
vertical axes in the parent ``PlotModel``. If there are more than one
18+
horizontal/vertical axis, the axes can be specified by the ``XAxisKey``
19+
and ``YAxisKey`` properties. This requires the ``Key`` property to be
20+
set on the desired axes.
21+
22+
Data
23+
----
24+
25+
Use the ``Items`` collection to add data to the ``HistogramSeries``:
26+
27+
.. code:: csharp
28+
29+
histogramSeries1.Items.Add(new HistogramItem(rangeStart: 0.0, rangeEnd: 0.5, area: 0.7));
30+
histogramSeries1.Items.Add(new HistogramItem(rangeStart: 0.5, rangeEnd: 0.75, area: 0.2));
31+
histogramSeries1.Items.Add(new HistogramItem(rangeStart: 0.75, rangeEnd: 1.0, area: 0.1));
32+
33+
You can generate a list of ``HistogramItem`` from sample data with one of the static ``Collect`` methods provided by the ``HistogramHelpers`` class.
34+
35+
.. code:: csharp
36+
37+
histogramSeries1.Items.AddRange(HistogramHelpers.Collect(samples), samples.Min(), samples.Max(), 10, true);
38+
39+
Alternatively, you can specify a collection in the ``ItemsSource``
40+
property.
41+
42+
- If the ``Mapping`` property is set, each element in the collection
43+
will be transformed
44+
- If the collection is a list of ``HistogramItem``, it will be used with no
45+
mapping
46+
47+
Tracker
48+
-------
49+
50+
The tracker format string may use the following arguments:
51+
52+
- ``{0}`` the title of the series
53+
- ``{1}`` the x-axis title
54+
- ``{2}`` the x-axis position
55+
- ``{3}`` the y-axis title
56+
- ``{4}`` the y-axis position
57+
- ``{5}`` the range start of the area
58+
- ``{6}`` the range end of the area
59+
- ``{7}`` the value (height) of the area
60+
- ``{8}`` the area (width * height) of the area
61+
- ``{PropertyX}`` the value of ``PropertyX`` in the item (extended format string syntax)
62+
63+
To show only the value with one digit, use the format string ``"{2:0.0}"``.
64+
65+
If an item was hit, it is also possible to use the extended format string syntax, e.g. ``{PropertyX:0.##}``, where the value of ``PropertyX`` will be found by reflection of the item.
66+
67+
The default tracker format string for ``HistogramSeries`` is ``"Start: {5}\nEnd: {6}\nValue: {7}\nArea: {8}"``
68+
69+
See `MSDN <http://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx>`_ for more information about format strings.
70+
71+
72+
Example
73+
-------
74+
75+
Here is an example making use of one of the ``HistogramHelpers.Collect`` methods to plot a distribution of samples drawn from a random distribution with 20 bins.
76+
77+
.. image:: HistogramSeries.png
78+
79+
.. sourcecode:: csharp
80+
81+
// prepare the model
82+
var model = new PlotModel()
83+
{
84+
Title = "Cubic Distribution",
85+
LegendPlacement = LegendPlacement.Outside,
86+
LegendPosition = LegendPosition.TopCenter,
87+
LegendOrientation = LegendOrientation.Horizontal
88+
};
89+
90+
// add two linear axes
91+
model.Axes.Add(new LinearAxis() { Title = "Observation", Position = AxisPosition.Bottom });
92+
model.Axes.Add(new LinearAxis() { Title = "Frequency", Position = AxisPosition.Left });
93+
94+
// generate random samples from a polynomial distribution
95+
double power = 3;
96+
double max = 10.0;
97+
int sampleCount = 1000;
98+
99+
double integral = Math.Pow(max, power + 1) / (power + 1);
100+
101+
var rnd = new Random(0);
102+
List<double> samples = new List<double>();
103+
for (int i = 0; i < sampleCount; i++)
104+
{
105+
samples.Add(Math.Pow(rnd.NextDouble() * (power + 1) * integral, 1.0 / (power + 1)));
106+
}
107+
108+
// plot histogram of samples
109+
var histogramSeries = new HistogramSeries()
110+
{
111+
Title = "Empirical Distribution",
112+
FillColor = OxyColors.Green,
113+
StrokeColor = OxyColors.Black,
114+
StrokeThickness = 2
115+
};
116+
histogramSeries.Items.AddRange(HistogramHelpers.Collect(samples, 0, max, 20, true));
117+
model.Series.Add(histogramSeries);
118+
119+
// plot ideal line for comparison
120+
var functionSeries = new FunctionSeries(x => Math.Pow(x, power) / integral, 0, max, 1000)
121+
{
122+
Title = "Ideal Distribution",
123+
Color = OxyColors.Red
124+
};
125+
model.Series.Add(functionSeries);
126+
127+
Color and Style
128+
---------------
129+
130+
The ``FillColor`` defines the color of the fill color of the areas. The default value is
131+
``Automatic``. In this case the color will be set automatically from the
132+
colors specified in the ``DefaultColors`` property of the parent ``PlotModel``.
133+
134+
The ``StrokeColor`` defines the color of the outline color of the areas. The default value is
135+
``OxyColors.Black``. The ``StrokeThickness`` defines the thickness of the area outline. The default value is ``0``
136+
137+
Labels
138+
---------------
139+
140+
The label format string may use the following arguments:
141+
142+
- ``{0}`` the value (height) of the area
143+
- ``{PropertyX}`` the value of ``PropertyX`` in the item (extended format string syntax)
144+
145+
The default label format string is ``null``, which prevents any label from being shown.
146+
147+
The ``LabelPlacement`` property may take any of the following parameters:
148+
149+
- ``Base`` the labels are positioned at the base of each area
150+
- ``Middle`` the labels are positioned at the middle of each area
151+
- ``Inside`` the labels are positioned at the extreme of each area, within the area
152+
- ``Outside`` the labels are positioned at the extreme of each area, outisde the area
153+
154+
This image shows the different options visually, with a ``LabelFormatString`` of ``{0}``.
155+
156+
.. image:: HistogramSeriesLabelPlacement.png
16.9 KB
Loading

models/series/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ See `MSDN <http://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110
5151
FunctionSeries.rst
5252
HeatMapSeries.rst
5353
HighLowSeries.rst
54+
HistogramSeries.rst
5455
IntervalBarSeries.rst
5556
LineSeries.rst
5657
PieSeries.rst

0 commit comments

Comments
 (0)