Skip to content

Commit

Permalink
Update HeatMapSeries examples
Browse files Browse the repository at this point in the history
  • Loading branch information
objorke committed Mar 31, 2016
1 parent 958c65a commit a93a735
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 137 deletions.
242 changes: 105 additions & 137 deletions models/series/HeatMapSeries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,58 +32,43 @@ Example (Linear, Bitmap)

.. sourcecode:: csharp

using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;

namespace ExampleLibrary
{

public class LinearHeatMapViewModel
{
private PlotModel modelP1;
public LinearHeatMapViewModel()
{
modelP1 = new PlotModel { Title = "Heatmap" };

//top axis
modelP1.Axes.Add(new LinearColorAxis
{
Palette = OxyPalettes.Rainbow(100)
});

//generate 1d normal distribution
var singleData = new double[100];
for(int x = 0; x < 100; ++x)
singleData[x] = Math.Exp((-1.0 / 2.0) * Math.Pow(((double)x - 50.0) / 20.0, 2.0));
//generate 2d normal distribution
var data = new double[100, 100];
for(int x = 0; x < 100; ++x)
for(int y = 0; y < 100; ++y)
data[y, x] = singleData[x] * singleData[(y + 30) % 100] * 100;

var heatMapSeries = new HeatMapSeries
{
X0 = 0,
X1 = 99,
Y0 = 0,
Y1 = 99,
Interpolate = true,
RenderMethod = HeatMapRenderMethod.Bitmap,
Data = data
};

modelP1.Series.Add(heatMapSeries);

}

public PlotModel Model1
{
get { return modelP1; }
set { modelP1 = value; }
}
}
}
var model = new PlotModel { Title = "Heatmap" };

// Color axis (the X and Y axes are generated automatically)
model.Axes.Add(new LinearColorAxis
{
Palette = OxyPalettes.Rainbow(100)
});

// generate 1d normal distribution
var singleData = new double[100];
for (int x = 0; x < 100; ++x)
{
singleData[x] = Math.Exp((-1.0 / 2.0) * Math.Pow(((double)x - 50.0) / 20.0, 2.0));
}

// generate 2d normal distribution
var data = new double[100, 100];
for (int x = 0; x < 100; ++x)
{
for (int y = 0; y < 100; ++y)
{
data[y, x] = singleData[x] * singleData[(y + 30) % 100] * 100;
}
}

var heatMapSeries = new HeatMapSeries
{
X0 = 0,
X1 = 99,
Y0 = 0,
Y1 = 99,
Interpolate = true,
RenderMethod = HeatMapRenderMethod.Bitmap,
Data = data
};

model.Series.Add(heatMapSeries);

Example (Categorized, Rectangle)
-------
Expand All @@ -96,88 +81,71 @@ It visualizes the amount of cake (y-axis) consumed on the specific day of week (

.. sourcecode:: csharp

using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;

namespace ExampleLibrary
{

public class LinearHeatMapViewModel
{
private PlotModel modelP1;
public LinearHeatMapViewModel()
{
modelP1 = new PlotModel { Title = "Cakes per Weekday" };

//WeekDay-Axis (Bottom)
modelP1.Axes.Add(new CategoryAxis
{
Position = AxisPosition.Bottom,
//Key used for specifying this axis in the HeatMapSeries
Key = "WeekDayAxis",
//Property of the items in ItemSource that should be used as title
LabelField = "Title",
//Array of Categories (see above), mapped to one of the coordinates of the 2D-data array
ItemsSource = new Category[]
{
new Category{ Title = "Monday" },
new Category{ Title = "Tuesday" },
new Category{ Title = "Wednesday" },
new Category{ Title = "Thursday" },
new Category{ Title = "Friday" },
new Category{ Title = "Saturday" },
new Category{ Title = "Sunday" }
}
});
//CakeType-Axis (Left)
modelP1.Axes.Add(new CategoryAxis
{
Position = AxisPosition.Left,
Key = "CakeAxis",
LabelField = "Title",
ItemsSource = new Category[]
{
new Category{ Title = "Apple cake" },
new Category{ Title = "Baumkuchen" },
new Category{ Title = "Bundt cake" },
new Category{ Title = "Chocolate cake" },
new Category{ Title = "Carrot cake" }
}
});
//color axis
modelP1.Axes.Add(new LinearColorAxis
{
Palette = OxyPalettes.Hot(200)
});

var rand = new Random();
var data = new double[7, 5];
for(int x = 0; x < 5; ++x)
for(int y = 0; y < 7; ++y)
data[y, x] = rand.Next(0, 200) * (0.13 * (y + 1));

var heatMapSeries = new HeatMapSeries
{
X0 = 0,
X1 = 6,
Y0 = 0,
Y1 = 4,
XAxisKey = "WeekDayAxis",
YAxisKey = "CakeAxis",
RenderMethod = HeatMapRenderMethod.Rectangles,
LabelFontSize = 0.2, //neccessary to display the label
Data = data
};

modelP1.Series.Add(heatMapSeries);

}

public PlotModel Model1
{
get { return modelP1; }
set { modelP1 = value; }
}
}
}
var model = new PlotModel { Title = "Cakes per Weekday" };

// Weekday axis (horizontal)
model.Axes.Add(new CategoryAxis
{
Position = AxisPosition.Bottom,

// Key used for specifying this axis in the HeatMapSeries
Key = "WeekdayAxis",

// Array of Categories (see above), mapped to one of the coordinates of the 2D-data array
ItemsSource = new[]
{
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
}
});

// Cake type axis (vertical)
model.Axes.Add(new CategoryAxis
{
Position = AxisPosition.Left,
Key = "CakeAxis",
ItemsSource = new[]
{
"Apple cake",
"Baumkuchen",
"Bundt cake",
"Chocolate cake",
"Carrot cake"
}
});

// Color axis
model.Axes.Add(new LinearColorAxis
{
Palette = OxyPalettes.Hot(200)
});

var rand = new Random();
var data = new double[7, 5];
for (int x = 0; x < 5; ++x)
{
for (int y = 0; y < 7; ++y)
{
data[y, x] = rand.Next(0, 200) * (0.13 * (y + 1));
}
}

var heatMapSeries = new HeatMapSeries
{
X0 = 0,
X1 = 6,
Y0 = 0,
Y1 = 4,
XAxisKey = "WeekdayAxis",
YAxisKey = "CakeAxis",
RenderMethod = HeatMapRenderMethod.Rectangles,
LabelFontSize = 0.2, // neccessary to display the label
Data = data
};

model.Series.Add(heatMapSeries);
Binary file modified models/series/HeatMapSeries_categorized.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified models/series/HeatMapSeries_linear.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a93a735

Please sign in to comment.