0
$\begingroup$

I have the following list :

Mdx = {{73024.8`, 28427.1`}, {51486.5`, 26994.3`}, {30663.3`, 
19068.`}, {42428.1`, 26226.2`}, {16337.4`, 17798.5`}, {46855.6`, 
39230.6`}};

List that I printed in the form of a BarChart:

MdxPlot = BarChart[Mdx, ImageSize -> 400, ChartStyle -> {LightGray, Automatic},ChartLayout -> "Grouped", ChartLegends -> Placed[LineLegend[{"EKV", "ASV"}, 
 LegendFunction -> (Framed[#, FrameMargins -> 0, 
     Background -> White] &)], {Right, Top}], AxesLabel -> {"", "Mdx [kNm]"}, ChartLabels -> {{"K1-1", "K2-3", "K1-4", "K1-5", "K1-6", "K1-7"}, 
None}, PlotLabel -> "X-Richtung", PlotRange -> {Full, {Automatic, Max[Mdx] + 10000}}]

Which give me this nice result :

enter image description here

Now I would like to place a list of value between the orange and the blue charts, this list represents the percentage difference between the two values.

DeltaX = {-61.07199198080653`, -47.57013974537015`, -37.81491228928393`, -38.18672059319177`,8.943283509003882`, -16.27340168517744`, -20.83293776466232`}

Wich would give :

enter image description here

Any ideas ?

$\endgroup$
2
$\begingroup$

You can use options of Labeled like the following:

Mdx = {{73024.8`, 28427.1`}, {51486.5`, 26994.3`}, {30663.3`, 
    19068.`}, {42428.1`, 26226.2`}, {16337.4`, 17798.5`}, {46855.6`, 
    39230.6`}};
dat1 = Mdx[[All, 1]];
dat2 = Mdx[[All, 2]];
dat3 = Transpose[{dat1, dat2}];
DeltaX = {-61.07199198080653`, -47.57013974537015`, \
-37.81491228928393`, -38.18672059319177`, 
   8.943283509003882`, -16.27340168517744`};
dat4 = MapThread[
   Labeled[#1, StringForm["      ``%", NumberForm[#2, 3]], Above, Red,
      12] &, {dat3, DeltaX}];
dat = Transpose[{dat1, dat2}];

MdxPlot = 
 BarChart[dat4, ImageSize -> 400, 
  ChartStyle -> {LightGray, Automatic}, ChartLayout -> "Grouped", 
  ChartLegends -> 
   Placed[LineLegend[{"EKV", "ASV"}, 
     LegendFunction -> (Framed[#, FrameMargins -> 0, 
         Background -> White] &)], {Right, Top}], 
  AxesLabel -> {"", "Mdx [kNm]"}, 
  ChartLabels -> {{"K1-1", "K2-3", "K1-4", "K1-5", "K1-6", "K1-7"}, 
    None}, PlotLabel -> "X-Richtung", 
  PlotRange -> {Full, {Automatic, Max[Mdx] + 10000}}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Exactly what I needed! $\endgroup$ – Jocelyn Minini Mar 17 at 10:15
2
$\begingroup$
percentdiffs = PercentForm /@ (- Subtract @@@ Mdx/Mdx[[All, 1]]);

BarChart[Thread[Labeled[Mdx, Style[#, Red, 14] & /@ percentdiffs, Above]], 
 ImageSize -> 500, 
 ChartLayout -> "Grouped", 
 ChartLegends -> Placed[LineLegend[{"EKV", "ASV"}, 
      LegendFunction -> (Framed[#, FrameMargins -> 0, Background -> White] &)], 
    {Right, Top}], 
 AxesLabel -> {"", "Mdx [kNm]"}, 
 ChartLabels -> { {"K1-1", "K2-3", "K1-4", "K1-5", "K1-6", "K1-7"}, None}, 
 PlotLabel -> "X-Richtung", 
 PlotRange -> {Full, {Automatic, Max[Mdx] + 10000}}]

enter image description here

Add the option ChartStyle -> {{LightGray, ColorData[97]@1}} to get

enter image description here

$\endgroup$
1
$\begingroup$

One way to do it is as follows. Use the following code:

Manipulate[
 DynamicModule[{pt1 = {1, 0}, pt2 = {4, 0}},
  loc = Graphics[{Blue, Thin, Circle[{0, 0}, 2]}, ImageSize -> 20];
  Column[{
    LocatorPane[Dynamic[{pt1, pt2}],
     Dynamic@
      Show[{
        
        (* Here your graphics starts *)
        Show[{
          MdxPlot,
          
          Graphics[{Text[Style["-61.07", 14, Red], pt1], 
            Text[Style["-47.57", 14, Red], pt2]}]
          }]
        (* Here your graphics ends *)
          }, ImageSize -> sz]
     , Appearance -> loc ],
                        
    Button["Print the list of points", Clear[points]; 
     points = {pt1, pt2}; Print[points]]
            }]
                            ], {sz, 250, 650}]

Please see that the code making the graphics you are working on is included between the lines: (* Here your graphics starts *) and (* Here your graphics ends *). The rest of the code is needed to comfortably position the text on your graphics.

Step one: evaluate the code. It returns the manipulator:

enter image description here

Using the slider sz make a comfortable size of the image.

Step two: Find two locators with the form of circles containing the texts at the bottom of the image and move them to the desired places.

enter image description here

Step three: Press the button "Print the list of points" at the bottom. This returns the list with the positions of the locators. The list is under the bottom of the manipulator.

enter image description here

Copy-paste the first of the coordinates of these points instead of pt1 and the second - instead of pt2 into the line

Graphics[{Text[Style["-37.81", 14, Red], pt1], 
  Text[Style["-38.18", 14, Red], pt2]}]

of the code.

Step four: Add the functions Text[Style["-61.07", 14, Red], pt1], Text[Style["-47.57", 14, Red] into the graphics statement and evaluate.

Repeat the procedure until you have introduced all text elements.

As soon as you have introduced all text elements into your plot, copy the part of the code staying between the lines: (* Here your graphics starts *) and (* Here your graphics ends *) and paste it somewhere in your notebook. Evaluate it. Done.

Have fun!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.