## plotting – How can I label a table of histograms with the names of the data symbols, not the data themselves?

How can I label a table of histograms with the names of the data symbols, not the data themselves?

If I want to make a table of plots with each plot labeled with the name of the function it plots, this is simple:

``````f[x_] := x; g[x_] := x^2;
Table[Plot[p[x], {x, -1, 1}, PlotLabel -> p], {p, {f, g}}]
``````

However, if I want to do the same for `Histogram`, I have not figured out how. I have tried various combinations using `ToString`, `Hold`, `HoldForm`, and `Unevaluated`, as well as `ChartLabels`. For example,

``````l = RandomReal[{0, 1}, 20]; m = RandomReal[{0, 1}, 20];
Table[Histogram[p, PlotLabel -> p], {p, {l, m}}]
``````

does not work, as the labels are the values of `l` and `m`, not the strings `l` and `m`.

The same question applies to the format analogous to

``````Plot[#[x], {x, -1, 1}, PlotLabel -> #] & /@ {f, g}
``````

which works for `Plot` but not for `Histogram`.

## printing – How can I compare histograms between a digital image and it’s print

I want to compare color histograms between a digital photo and its physically printed in cloth (like a tshirt) version. The process is simple:

1. Printing a digital image (with good resolution) in a tshirt
2. Take a picture of that printed tshirt in proper aligment and crop
3. Compare histograms

As one might expect, the color histogram of the photo of the printed tshirt is very different from the original image, as it should be. What I want to know is if there is any known method to achieve one of the following:

1. From original digital image, transform colors so to be closer to printed colorspace histogram.
2. From printed tshirt photo, try to normalize or transform in some way to achieve back original colors.

I am aware that the color distribution of the printed tshirt depend also on the camera that captures it. Right now I am thinkig of training a ML model to try to learn the color transformation between two colors distributions (original and physically printed).

However, I wonder if there is some literature about that or some procedure I can perform using my camera to try to find that color transformation so I can apply to other prints.

My goal is to generalize (predict) the printed color distribution transformation from original digital image. As I’m always using the same printer for print, and the same camera for the photo of the tshirt, I guess this should be feasible.

## Comparing histograms between a digital image and it’s print

I want to compare color histograms between a digital photo and its physically printed in cloth (like a tshirt) version. The process is simple:

1. Printing a digital image (with good resolution) in a tshirt
2. Take a picture of that printed tshirt in proper aligment and crop
3. Compare histograms

As one might expect, the color histogram of the photo of the printed tshirt is very different from the original image, as it should be. What I want to know is if there is any known method to achieve one of the following:

1. From original digital image, transform colors so to be closer to printed colorspace histogram.
2. From printed tshirt photo, try to normalize or transform in some way to achieve back original colors.

I am aware that the color space of the printed tshirt depend also on the camera that captures it. Right now I am thinkig of training a ML model to try to learn the color transformation between two colors spaces (original and physically printed).

However, I wonder if there is some literature about that or some procedure I can perform using my camera to try to find that color transformation so I can apply to other prints.

My goal is to generalize (predict) the printed color space transformation from original digital image. As I’m always using the same printer for print, and the same camera for the photo of the tshirt, I guess this should be feasible.

## Cannot combine graphic objects while plotting two Smooth Histograms

I am trying to plot two smooth histograms, which I’m generating separately so I can chose their PlotStyle separately. When I run the code, it says I cannot combine the two graphic objects. What am I doing wrong?

Thanks,
Sid

``````CloudDeploy[
FormPage[{"k1" -> "Number", "n1" -> "Number", "n2" -> "Number",
"k2" -> "Number", "n3" -> "Number", "n4" -> "Number"},

fig1 = SmoothHistogram[
Table[Table[
If[RandomReal[] > #k1, RandomChoice[{100, 90}],
RandomChoice[{80, 70, 60, 50, 40}]], #n1], #n2],
PlotStyle -> Red] &;
fig2 = SmoothHistogram[
Table[Table[
If[RandomReal[] > #k2, RandomChoice[{100, 90}],
RandomChoice[{40, 30, 20, 10, 0}]], #n3], #n4] ,
PlotStyle -> Gray] &;

Show[{fig1, fig2}]]]
``````

## plotting – Changing the color and thickness of smooth histograms of two sets curves on the same graph

I have a code (shown below) where I generate two different sets of data and plot the two sets as a smooth histogram on the same graph. The code works pretty well.

What I’m having an issue with is changing the color and thickness of the two sets of data separately.

As shown in the code, I used Plotstyle->{{Red}, {Gray}}, but what that does is, it divides half the curves into Red and half into Gray. It works fine if both sets of data have the same number of curves, but not so much when there is a big difference.

What can I do here?

``````k = 0.6;
n1 = 10;
n2 = 10;
k1 = 0.4;
n3 = 3;
n4 = 3;
data1 = Table(
Table(If(RandomReal() > k, RandomChoice({100, 90}),
RandomChoice({80, 70, 60, 50, 40})), n1), n2);
data2 = Table(
Table(If(RandomReal() > k1, RandomChoice({100, 90}),
RandomChoice({40, 30, 20, 10, 0})), n3), n4);

SmoothHistogram({data1, data2}, PlotStyle -> {{Red}, {Gray}},
ImageSize -> Large)
``````

Thanks,
Sid

## style – color distinguish two smooth histograms

I want to color distinguish my two smooth histograms, I am not able to do so. I am writing the following but it is not working, Can you aid?

``````data1 = RandomVariate[NormalDistribution[0, 1], {100, 2}];

data2 = RandomVariate[NormalDistribution[1, 1], {100, 2}];

Show[SmoothHistogram3D[data1], SmoothHistogram3D[data2],
PlotRange -> All]

Show[ColorFunction -> "DarkRainbow"]
``````

## ticks – Why are these two histograms plotting so differently?

I have two lists, which are pretty similar. They are given by:

``````list1=Flatten[Table[#[[1]], #[[2]]] & /@ {{1, 2},{2, 9},{3, 3},{4,73},{5, 38}}]
list2=Flatten[Table[#[[1]], #[[2]]] & /@ {{1, 2},{2, 10},{3, 8},{4,65},{5, 22}}]
``````

ie. list1 is a list of 2 1’s, 9 2’s, 3 3’s, etc.

If I plot a histogram of them next to each other they come out like this:

``````{Histogram[list1],Histogram[list2]}
``````

And I can’t figure out why the labelling is different. I would like to have all of my numbers in the centre of the column, so tried using the answer from this question. as so:

``````{Histogram[list1,
Ticks -> {{# + .5, #} & /@ HistogramList[list1][[1]], Automatic}],
Histogram[list2,
Ticks -> {{# + .5, #} & /@ HistogramList[list2][[1]], Automatic}]}
``````

But that comes out like this:

Any idea what’s going on?

## applications – Are histograms with varying class widths ever used in the real world?

It seems that every math textbook that teaches histograms teaches how to calculate frequency density, which is needed for cases where class widths (i.e. range of data covered by each bar in the histogram) are not uniform. Maybe the range for one class is 10 and the range for another is 20, for example.

Are histograms of this type actually used in the real world?

I ask because despite hours of searching and trying out many different chart creating programs (including Excel and other popular spreadsheet software, along with many freemium online tools for creating custom charts and graphics for data). Despite searching I’ve yet to find a single program that allows for specifying a custom width for each class. It would be a very simple function for these programs to include but the conspicuous absence of it makes me think it’s not there for a reason.

For context, I’m a teacher and I’m trying to create my own histograms of this type (with inconsistent class widths) to show my students and tell them about a digital way to create these histograms instead of having to draw them by hand or some painting program. I get that R or SPSS or SAS can probably do this, but given the complexity of those programs that seems like overkill for what in theory is a very simple problem.

## Quantification of the similarity / difference between two probability histograms in Mathematica

I am trying to estimate the similarity / overlap or vice versa the difference between two probability histograms in Mathematica.

There are two integrated measures that I discovered in Mathematica, namely the one `KolmogorovSmirnovTest` and the `PearsonChiSquareTest`. The problem I encounter is that when calculating the two histograms for data sets with very different sample sizes, the estimates become almost zero even though the two distributions are almost the same (example below).

Example:

``````n1 = 90000;
n2 = 20000;
RandomSeed(100);
ls1 = RandomInteger({1, 10}, n1);
RandomSeed(101);
ls2 = RandomInteger({1, 10}, n2);

hist1 = Histogram(ls1, {1}, "Probability",
AxesLabel -> {"value", "probability"}, ChartStyle -> {Yellow},
ChartLegends -> {"List 1"});
hist2 = Histogram(ls2, {1}, "Probability",
AxesLabel -> {"value", "probability"},
ChartStyle -> {Directive(Red, Opacity(0.5))},
ChartLegends -> {"List 2"});
``````

a) Sample sizes `n1=90000` and `n2=20000` very different:

``````KolmogorovSmirnovTest(ls1, ls2)
PearsonChiSquareTest(ls1, ls2)
``````

0.603708

0.389257

b) Sample sizes `n1=30000` and `n2=20000` more comparable:

``````KolmogorovSmirnovTest(ls1, ls2)
PearsonChiSquareTest(ls1, ls2)
``````

0.999966

0.993693

which are closer to the (intuitively) expected values. But case a) leads to much lower estimates and far below $$1$$.

When visually comparing the histograms, however, they overlap almost perfectly and are almost equally uniform in both cases:

Applying these measures to `hist1` and `hist2` is not possible, but try the following:

``````KolmogorovSmirnovTest(HistogramList(ls1, {1}, "Probability")((2)),
HistogramList(ls2, {1}, "Probability")((2)))
PearsonChiSquareTest(HistogramList(ls1, {1}, "Probability")((2)),
HistogramList(ls2, {1}, "Probability")((2)))
``````

leads to similar results, that is, far below $$1.$$

1. Is there a way to continue using these built-in functions despite very different sample sizes (from which the individual histograms are calculated)? That is, the distributions are compared regardless of the sample size from which they come.

2. Are there other related metrics in Mathematica that can be used to quantify how similar (or how much they overlap) two probability histograms are?

## Histograms – SmoothHistrogram records only one record of two

I generated two records from the same process, but when I try to draw them, only one seems to work. It's probably just a mistake, but I can not really understand why it happens.

``````f(y_, n_) :=
n*Exp(-n^2/y)/(Sqrt(Pi)*y^((n + 3)/2))*(HermiteH(
n, (y + 2 n)/(2*Sqrt(y))) -
Sqrt(y)*HermiteH(n - 1, (y + 2 n)/(2*Sqrt(y))))

data2 = Import("sum distr .dat");
data2 = Flatten(data2)
p1 = SmoothHistogram(data2, 5, PlotRange -> {{0, 2000}, {0, 0.004}})
p2 = Plot(f(y, 500), {y, 500, 2000}, PlotRange -> All,
PlotStyle -> {Red, Dashed, Thick})
Show(p1, p2)

data3 = Import("sum distr1 .dat");
data3 = Flatten(data3)
p3 = SmoothHistogram(data3, 5, PlotRange -> {{0, 2000}, {0, 0.004}})
p2 = Plot(f(y, 500), {y, 500, 2000}, PlotRange -> All,
PlotStyle -> {Red, Dashed, Thick})
Show(p1, p3)
``````