How can I set the maximum scale on a LinearColorAxis for an OxyPlot heatmap

105 Views Asked by At

I am using OxyPlot 2.0. I would like to create several heatmaps that all use the same color scale. The minimum will always be zero, so I need to set the maximum. I show the code from my view model below. If the user has set a lock on the scale, then I include the max value, set by the user, in the LinearColorAxis. This happens just before I return the PlotModel. The set value needs to be greater than the maximum value in any data set. The code that I show below is not working. I suspect that the LinearColorAxis is recalculated just before the plot is rendered. Is there any way to update the axis before it is rendered?

    public PlotModel CreatePlot()
    {
        // heatmap series
        var hs = CreateHeatMap();

        // color axis for heatmap
        var colorAxis = new LinearColorAxis
        {
            Position = AxisPosition.Right,
            Palette = ColorMaps.GetReverseMap(_colorMapName, 500),
        };

        // contour series
        var cs = CreateContours();

        try
        {
            if (cs.ContourLevels.Length > 1)
                cs.CalculateContours();
        }
        catch (Exception e)
        {
            Console.WriteLine(@"Contour calculation failed.");
            IssueReport.HandleException(e);
        }

        // logarithmic axes
        var logxAxis = new LockableLogarithmicAxis
        {
            Position = AxisPosition.Bottom,
            Title = "Resistivity of Approaching Bed (ohm-m)",
            MajorGridlineStyle = LineStyle.Solid,
            MinorGridlineStyle = LineStyle.None,
            //MinorTickSize = 0.0,
            Key = "logx",
            IsPanEnabled = false,
            IsZoomEnabled = false,
            IsAxisVisible = _scanParameter == ScanParameter.RemoteLayer
        };

        var logyAxis = new LockableLogarithmicAxis
        {
            Position = AxisPosition.Left,
            Title = "Resistivity of Tool Formation (ohm-m)",
            MajorGridlineStyle = LineStyle.Solid,
            MinorGridlineStyle = LineStyle.None,
            //MinorTickSize = 0.0,
            Key = "logy",
            IsPanEnabled = false,
            IsZoomEnabled = false
        };

        // linear axes
        var linxAxis = new LinearAxis
        {
            Position = AxisPosition.Bottom,
            Title = "Tool Inclination (deg)",
            IsAxisVisible = _scanParameter == ScanParameter.Inclination,
            MajorGridlineStyle = LineStyle.Solid,
            MinorGridlineStyle = LineStyle.None,
            Key = "linx",
            IsPanEnabled = false,
            IsZoomEnabled = false
        };

        var linyAxis = new LinearAxis
        {
            Position = AxisPosition.Left,
            IsAxisVisible = false,
            MajorGridlineStyle = LineStyle.Solid,
            MinorGridlineStyle = LineStyle.None,
            Key = "liny",
            IsPanEnabled = false,
            IsZoomEnabled = false
        };

        // set up plotModel
        if (_settingsViewModel != null)
        {
            var inc = "Incl = " + _settingsViewModel.ToolInclinationDegrees;
            var remoteResistivity = "Remote Resistivity = " + _settingsViewModel.RemoteLayerResistivity;
            var constantParameter = _scanParameter == ScanParameter.RemoteLayer
                ? inc
                : remoteResistivity;

            var units = _plotUnits == PlotUnitsEnum.Meters ? "(m)" : "(ft)";
            var dodSignal = _settingsViewModel.ThresholdDodSignal;

            var title = dodSignal == ThresholdDodSignal.Best ? $"Best DoD {units} from Threshold" : $"Average DoD {units} from Threshold";
            if (MainWindowViewModel.AppSettings.DodAlgorithm == DodAlgorithm.Sensitivity)
                title = $"Average DoD {units} from Sensitivity";
            _fullTitle = _toolName + ", " + constantParameter + ", " + title;
        }
        var plotModel = new PlotModel { Title = _fullTitle };
        plotModel.Series.Add(hs);
        if (cs.ContourLevels.Length > 1)
            plotModel.Series.Add(cs);
        plotModel.Axes.Add(logxAxis);
        plotModel.Axes.Add(logyAxis);
        plotModel.Axes.Add(linxAxis);
        plotModel.Axes.Add(linyAxis);
        plotModel.Axes.Add(colorAxis);
        plotModel.DefaultFontSize = 16;

        if (MainWindowViewModel.AppSettings.LockMaxValueHeatmap)
        {
            var maxScaleValue = MainWindowViewModel.AppSettings.MaxValueHeatmap;
            colorAxis.Include(maxScaleValue);
        }

        return plotModel;
    }

Edit:

Here is the code that generates the heatmap

        var hs =  new HeatMapSeries
        {
            Data = zData,
            XAxisKey = xAxisKey,
            YAxisKey = "logy",
            X0 = _linearX[0],
            X1 = _linearX[_linearX.Length - 1],
            Y0 = _linearY[0],
            Y1 = _linearY[_linearY.Length - 1],
            TrackerFormatString = trackerFormatString,
            Tag = "heatmap",
        };

The heatmap specifies the x and y axes used, but not the color axis. I assume the correct color axis get assigned at some point, as it is the only color axis in PlotModel.Axes. The point is that the LinearColorAxis created in the view model has no information about the data to be plotted, at that point. I am guessing that the setting of the color axis happens just before rendering.

0

There are 0 best solutions below