示例#1
0
        public void Test_Heatmap_AutoScaling()
        {
            // https://github.com/ScottPlot/ScottPlot/issues/1485

            double[,] intensities = new double[100, 100];
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    intensities[i, j] = (Math.Sin(i * .2) + Math.Cos(j * .2)) * 100;
                }
            }

            var plt = new ScottPlot.Plot(500, 400);

            var hmap = plt.AddHeatmap(intensities, ScottPlot.Drawing.Colormap.Viridis, lockScales: false);

            hmap.Interpolation = InterpolationMode.Bicubic;

            var cbar = plt.AddColorbar(hmap);

            double[] tickPositions = ScottPlot.DataGen.Range(-150, 150, 50, true);
            string[] tickLabels    = tickPositions.Select(x => x.ToString()).ToArray();
            cbar.SetTicks(tickPositions, tickLabels, -200, 200);

            plt.Margins(0, 0);
            TestTools.SaveFig(plt);
        }
示例#2
0
        public void Test_Colorbar_CanBeAdded()
        {
            var plt  = new ScottPlot.Plot();
            var bmp1 = TestTools.GetLowQualityBitmap(plt);

            plt.AddColorbar();
            var bmp2 = TestTools.GetLowQualityBitmap(plt);

            //TestTools.SaveFig(plt);
            var before = new MeanPixel(bmp1);
            var after  = new MeanPixel(bmp2);

            Assert.That(after.IsDarkerThan(before));
        }
示例#3
0
        public void Test_Colorbar_ColorCanBeChanged()
        {
            var plt  = new ScottPlot.Plot();
            var cb   = plt.AddColorbar(ScottPlot.Drawing.Colormap.Grayscale);
            var bmp1 = TestTools.GetLowQualityBitmap(plt);

            cb.UpdateColormap(ScottPlot.Drawing.Colormap.Blues);
            var bmp2 = TestTools.GetLowQualityBitmap(plt);

            //TestTools.SaveFig(plt);
            var before = new MeanPixel(bmp1);
            var after  = new MeanPixel(bmp2);

            Assert.That(before.IsGray());
            Assert.That(after.IsNotGray());
            Assert.That(after.IsMoreBlueThan(before));
        }
示例#4
0
        public void Test_Colormap_LayoutCanBeReset()
        {
            var plt = new ScottPlot.Plot(400, 300);

            plt.Style(figureBackground: System.Drawing.ColorTranslator.FromHtml("#dadada"));
            var bmpOriginal = new MeanPixel(plt.GetBitmap());

            var cb = plt.AddColorbar();
            var bmpWithColorbar = new MeanPixel(plt.GetBitmap());

            plt.Remove(cb);
            plt.YAxis2.ResetLayout();
            var bmpWithColorbarRemoved = new MeanPixel(plt.GetBitmap());

            Assert.AreNotEqual(bmpOriginal, bmpWithColorbar);
            Assert.AreEqual(bmpOriginal, bmpWithColorbarRemoved);
        }
示例#5
0
        public void Test_Heatmap_ManualScaling()
        {
            // The goal is to span the whole colormap only over values 0-200
            // even though the original data has many values outside this range.
            // https://github.com/ScottPlot/ScottPlot/issues/1485

            double[,] intensities = new double[100, 100];
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    intensities[i, j] = (Math.Sin(i * .2) + Math.Cos(j * .2)) * 100;
                }
            }

            var plt = new ScottPlot.Plot(500, 400);

            var cmap = ScottPlot.Drawing.Colormap.Viridis;

            var hmap = plt.AddHeatmap(intensities, cmap, lockScales: false);

            hmap.Interpolation = InterpolationMode.Bicubic;
            hmap.ScaleMin      = 0;
            hmap.Update(intensities, cmap, min: 0, max: 200); // intentionally cut-off data
            Console.WriteLine(hmap.ScaleMin);

            double[] tickPositions = ScottPlot.DataGen.Range(0, 200, 25, true);
            string[] tickLabels    = tickPositions.Select(x => x.ToString()).ToArray();

            var cbar = plt.AddColorbar(hmap);

            cbar.SetTicks(tickPositions, tickLabels, 0, 200);

            plt.Margins(0, 0);
            TestTools.SaveFig(plt);
        }