How to overlay multiple Histograms on one chart?

Hello,

I would like to overlay 5 histograms on one single chart with different colors and legends such that they could be distinguishable, but I am not able to do that. I appreciate any suggestions!

I have 5 data sets called "Dist_a", "Dist_b", "Dist_c", "Dist_d", "Dist_e", where I would like each histogram has a different color with its associated legend of {"a","b","c","d"}. I can plot them one by one as follows, but I would like to have all of them on a single chart (or window). Thanks!

Here is my code for a single histogram:

struct plotControl myPlot;
myPlot = plotGetDefaults("xy");

plotCanvasSize("px", 600 | 600);

plotSetTextInterpreter(&myPlot, "LaTeX", "legend");

plotSetLegendFont(&myPlot, "arial", 14);

plotSetLegendBkd(&myPlot, 0);

plotSetTitle(&myPlot, "Case A", "Arial", 16);
plotSetXLabel(&myplot, "x", "Arial", 14);
plotSetYLabel(&myplot, "Histogram", "Arial", 14);
plotSetYrange(&myPlot, 0, 400);
plotSetTicLabelFont(&myPlot, "arial", 14);
plotHist(myPlot, Dist_a,20);

 

1 Answer

0
accepted

You can use plotAddHist to combine multiple histograms in the same plot. For example:

new;
cls;

nobs = 100;

// Make sample data for example
dist_a = rndn(nobs, 1);
dist_b = rndn(nobs, 1) + 3;
dist_c = rndn(nobs, 1) - 3;

struct plotControl myPlot;
myPlot = plotGetDefaults("hist");

// Set up legend before first call
plotSetTextInterpreter(&myPlot, "LaTeX", "legend");
legend_items = "Dist_a" $| "Dist_b" $| "Dist_c";
plotSetLegend(&myPlot, legend_items);

// Draw first historgram
plotHist(myPlot, dist_a, 20);

// Add histograms for dist_b and dist_c
plotAddHist(dist_b, 20);
plotAddHist(dist_c, 20);


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy