Skip to content

Instantly share code, notes, and snippets.

@mdfarragher
Created November 7, 2019 14:23
Show Gist options
  • Save mdfarragher/d0851dfe795145f8a2736a3cfa25a533 to your computer and use it in GitHub Desktop.
Save mdfarragher/d0851dfe795145f8a2736a3cfa25a533 to your computer and use it in GitHub Desktop.
// a helper class to access the new binned columns
public class BinnedHouseBlockData
{
public float BinnedLongitude { get; set; }
public float BinnedLatitude { get; set; }
public float MedianHouseValue { get; set; }
}
// get an array of binned housing data
var binnedHhouses = context.Data.CreateEnumerable<BinnedHouseBlockData>(transformedData, reuseRowObject: false).ToArray();
// plot median house value by binned latitude and longitude
var chart = Chart.Plot(
new Graph.Scattergl()
{
x = binnedHhouses.Select(v => v.BinnedLongitude),
y = binnedHhouses.Select(v => v.BinnedLatitude),
mode = "markers",
marker = new Graph.Marker()
{
symbol = "square",
size = 32,
color = binnedHhouses.Select(v => v.MedianHouseValue),
colorscale = "Jet"
}
}
);
chart.WithXTitle("Binned Longitude");
chart.WithYTitle("Binned Latitude");
chart.WithTitle("Median house value by binned location");
chart.Width = 600;
chart.Height = 600;
display(chart);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment