2
$\begingroup$

I have the following image:

enter image description here

I want to draw ten horizontal lines (per 5% interval shown) stretching across the image and starting at the y-axis. The intention is to read the exact height of each bar. How can I do this with Mathematica? Or, if my approach doesn't make sense, is there a better way of reading these heights?

Thanks for your help.

$\endgroup$

2 Answers 2

3
$\begingroup$

Your aim is to get the heights of the bars in %. As you only has a picture, you need to read the heights in some way. Toward this aim, copy the picture and paste it into Mathematica. Then enlarge it by dragging. Now you right click into the picture and choose "Get Coordinates".

With the help of "Get Coordinates" you read the y coordinate of the 0% line: y0 and the y coordinate of the 20% line: y20 (note your values will be different because they depend on the magnification). Next you read the coordinates of the top of the bars and subtract y0: heights:

y0 = 23;
y20 = 161;
heights = {84, 101, 138, 126, 148, 95, 61, 63, 41, 35, 53} - y0;

The heights of the bars are now given by:

heights/(y20 - y0) 20.
(* {8.84058, 11.3043, 16.6667, 14.9275, 18.1159, 10.4348, 5.50725, \
5.7971, 2.6087, 1.73913, 4.34783} *)
$\endgroup$
2
$\begingroup$
im = Import["https://i.sstatic.net/MQgSHm.jpg"];
im3 = Binarize@ImageTrim[im, {{43, 32}, {320, 232}}]
bars = First@ImagePartition[im3, {25, 278}]
dataFound = 
 Tally /@ (ImageData[bars[[#]]][[2 ;; -2]][[All, 10]] & /@ 
      Range[1, Length@bars]) /. {{a_, b_}, {c_, d_}} :> (d/(b + d)) * 
     20 // N
{8.8, 11.3, 16.8, 15.1, 18.5, 10.5, 5.4, 5.9, 2.5, 1.7, 4.2}
GraphicsRow[{BarChart[dataFound, BarSpacing -> 0.8, 
   PlotRange -> {0, 20}, AspectRatio -> 0.66], im}]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ bchart = BarChart[dataFound , ChartLabels -> Range[1, 10]~Join~{">10"} , BarSpacing -> 0.8 , PlotRange -> {0, 20} , AspectRatio -> 0.66 , Frame -> True ] $\endgroup$
    – Syed
    Commented Nov 2, 2022 at 14:21
  • 1
    $\begingroup$ If you have a question about AspectRatio then please start a new post. $\endgroup$
    – Syed
    Commented Nov 2, 2022 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.