HeatMapSeries Axis Problems [Solved]

Oystein Bjorke 10 років тому 0
This discussion was imported from CodePlex

guevara123 wrote at 2013-03-08 13:21:

Hello !


I am currently trying to create a STFT Plot with HeatMapSeries, but i encountered a problem with setting the axis right..

Image
As you can see both axis have the same size and i dont know why.. My time-Axis(x-Axis) should be much smaller. The strange thing is, when I plot the HeatMap with flipped Axis( time- axis = y- axis, frequency axis -> x-axis ), than the plot is correctly drawn.

Here the interesting parts of the code:
 double x0 = 0;
 double x1 = currentTime; 
 double y0 = 0;
 double y1 =  maxFrequency;
 peaksData = .magnitudedata; // double[currenTime.Length, maxFrequency.Length]
heatMap = new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData };
            
            temp.Series.Add(heatMap);            
            var cs = new ContourSeries
            {
                Color = OxyColors.Black,
                FontSize = 0,
                ContourLevelStep = 1,
                LabelBackground = null,
                ColumnCoordinates =timeValues, //array with length = currenTime(rounded)
                RowCoordinates= frequenyValues,//array with length = maxFrequency
                Data = peaksData
            };
The same happens for the HeatMapSeries Example when I change the values to,
            double x0 = 3;
            double x1 = 4;
            double y0 = 5;
            double y1 = 8;
then i will get a lot of white space in the Plot..



Thanks in advance for your help.

guevara123 wrote at 2013-03-11 20:23:

Can noone help here?

guevara123 wrote at 2013-03-13 14:29:

There is a bug in HeatMapseries:
    /// <summary>
    /// Updates the max/minimum values.
    /// </summary>
    protected internal override void UpdateMaxMin()
    {
        [...]

        this.XAxis.Include(this.MinX);
        this.XAxis.Include(this.MaxX);
        this.YAxis.Include(this.MinY);     //this.XAxis.Include(this.MinY);
        this.YAxis.Include(this.MaxY);    //this.XAxis.Include(this.MaxY);
       [...]
    }


objo wrote at 2013-03-13 20:28:

Thanks for the bug report and solution! I have submitted the change.

NejibCh wrote at 2013-04-27 05:53:

I had some issues and liked to share after I solved them.
I had many challenges to set the contours, contour labels and colorAxis position (Needed to add a transparent axis to push the ColorAxis further for plotArea)
By the way this is great tool. Much better than some marketed tools "like Infragistics for example).
Good job guys.

!!!!!!!!!!!!!!!!!!!!!!!!!!! ----------------------- in the XAML

<Window x:Class="TreeMapInfragistics.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"
    xmlns:oxy2="clr-namespace:OxyPlot.Series;assembly=OxyPlot"
    Title="MainWindow" Height="610" Width="610">
<Grid>
    <oxy:Plot x:Name="MyOxyPlot" Model="{Binding MyPlotModelTab3}"/>
</Grid>
</Window>


!!!!!!!!!!!!!!!!!!!!!!!!!!! ----------------------- in the ViewModel

using System;
using System.Linq;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;

namespace HeatMapWithContours
{
public class MainViewModel: BaseViewModel
{
    public double [] mnMxXY = new double[6];
    public double[] WOB;
    public double[] RPM;

    public MainViewModel()
    {
        UpdateChart();
    }

   // ..........................................
   private PlotModel _myPlotModelTab3;
   public PlotModel MyPlotModelTab3
   {
       get { return _myPlotModelTab3; }
       set
       {
           _myPlotModelTab3 = value;
           OnPropertyChanged("MyPlotModelTab3");
       }
   }

   public void UpdateChart()
   {
       double[,] MyData = GenerateData();

       #region  HeatMapSeries

       var hm = new HeatMapSeries();
       hm.Data = MyData;
       hm.Selectable = false;
       hm.X0 = mnMxXY[0]; // Min X-axis
       hm.X1 = mnMxXY[1]; // Max X-axis

       hm.Y0 = mnMxXY[2]; // Min Y-axis
       hm.Y1 = mnMxXY[3]; // Max Y-axis

       #endregion

       #region ContourSeries

       var cs = new ContourSeries()
       {
           // ..............
           ColumnCoordinates = WOB, //yvalues
           RowCoordinates = RPM,//xvalues
           Data = MyData,

           // ............
           ContourLevelStep = 5,
           StrokeThickness = 0.5,
           LineStyle = LineStyle.Solid,
           Color = OxyColors.Gray,
           //ContourColors = new[] { OxyColors.SeaGreen, OxyColors.RoyalBlue, OxyColors.IndianRed },

           // ...............
           LabelFormatString = "[0.00]",
           LabelBackground = null,
           //LabelSpacing  = double.NaN,
           //Font = null,
           //LabelStep = 10,
           FontSize = 11,
           FontWeight = FontWeights.Normal,
           TextColor = OxyColors.Black
           //Background = OxyColor.FromAColor(220, OxyColors.White),
           //TrackerFormatString = null,

       };

       #endregion

       #region X- Axis

       LinearAxis xAxis = new LinearAxis
       {
           Position = AxisPosition.Bottom,
           Title = "RPM",
           ClipTitle = true,
           TitlePosition = 0.5,
           MinorGridlineStyle = LineStyle.Dot,
           MajorGridlineStyle = LineStyle.Dot,
           MinorGridlineThickness = 1,
           MajorGridlineThickness = 1,
           IsAxisVisible = true,
           IsZoomEnabled = false,
           IsPanEnabled = false,
           Angle = 0,
           AxisTitleDistance = 4,
           AxisTickToLabelDistance = 4,
           MajorTickSize = 7,
           MinorTickSize = 4,
           Minimum = mnMxXY[0],
           Maximum = mnMxXY[1],
           ShowMinorTicks = true
       };

       #endregion

       #region Y- Axis

       LinearAxis yAxis = new LinearAxis
       {
           Position = AxisPosition.Left,
           Title = "WOB",
           ClipTitle = true,
           TitlePosition = 0.5,
           MinorGridlineStyle = LineStyle.Dot,
           MajorGridlineStyle = LineStyle.Dot,
           MinorGridlineThickness = 1,
           MajorGridlineThickness = 1,
           IsAxisVisible = true,
           IsZoomEnabled = false,
           IsPanEnabled = false,
           Angle = 0,
           AxisTitleDistance = 4,
           AxisTickToLabelDistance = 4,
           MajorTickSize = 7,
           MinorTickSize = 4,
           Minimum = mnMxXY[2],
           Maximum = mnMxXY[3],
           ShowMinorTicks = true
       };

       #endregion

       #region Y1- Axis

       LinearAxis y2Axis = new LinearAxis
       {
           Position = AxisPosition.Right,
           IsAxisVisible = true,
           IsZoomEnabled = false,
           IsPanEnabled = false,

           TicklineColor = OxyColors.Transparent,
           AxislineColor = OxyColors.Transparent,
           TextColor = OxyColors.Transparent
       };

       #endregion

       #region ColorAxis

       ColorAxis cAxis = new ColorAxis
       {
           Position = AxisPosition.Right,
           PositionTier = 1,
           Palette = OxyPalettes.Jet(500),
           HighColor = OxyColors.Red,
           LowColor = OxyColors.Blue,
           Minimum = mnMxXY[4],
           Maximum = mnMxXY[5],
           StartPosition = 0.05,
           EndPosition = 0.95,
           IsAxisVisible = true,
           Angle = 0,
           AxisTitleDistance = 4,
           AxisTickToLabelDistance = 4,
           MajorTickSize = 7,
           MinorTickSize = 4,
           ShowMinorTicks = true,
           UseSuperExponentialFormat = true
       };

       #endregion

       #region PlotModel

       PlotModel tempPlotModel = new PlotModel();

       tempPlotModel.AutoAdjustPlotMargins = true;
       tempPlotModel.PlotAreaBackground = OxyColors.Red;
       tempPlotModel.Title = "Critical Speed Map (XPos)";
       tempPlotModel.TitleFontWeight = FontWeights.Normal;
       tempPlotModel.PlotAreaBorderThickness = 1;
       tempPlotModel.PlotAreaBorderColor = OxyColors.Black;

       tempPlotModel.Axes.Add(xAxis);
       tempPlotModel.Axes.Add(yAxis);
       tempPlotModel.Axes.Add(y2Axis);

       tempPlotModel.Axes.Add(cAxis);
       tempPlotModel.Series.Add(hm);
       tempPlotModel.Series.Add(cs);

       #endregion

       MyPlotModelTab3 = tempPlotModel;
  }

   #region Generate Data

   private double[,] GenerateData()
   {
            ..........
       }
}
}