3
$\begingroup$
n=20;
list4 = {1.0526315786138172`, 0.5555555541663151`, 
0.3921568573075441`, 0.3124999796694264`, 0.2666665956722264`, 
0.23809500179235274`, 0.21977946619291758`, 0.2083310131665477`, 
0.20201326465717925`, 0.19997974697283805`, 0.20196217882320022`, 
0.2081693710585961`, 0.2193206639825469`, 0.23680903638241013`, 
0.2630389206743215`, 0.3020407644466671`, 0.36053999654125235`, 
0.4497305815804302`, 0.5879697753001203`};
list6 = Table[i, {i, 1, n - 1, 1}];
list5 = {0.9803217312564441`, 0.48891346032810523`, 
0.3300180618700858`, 0.2538647255576357`, 0.21065863530452583`, 
0.18392405414737623`, 0.16670585871480148`, 0.15562904373342287`, 
0.1489303764483624`, 0.1456860926197184`, 0.14548235706853685`, 
0.14828607398305826`, 0.15443178324443788`, 0.16471559675381398`, 
0.18063370181566454`, 0.20487923953730616`, 0.24232040074890238`, 
0.30183038312423593`, 0.3993773303034516`};
list6 = Table[i, {i, 1, n - 1, 1}];
BarChart[{list4, list5}, 
ChartStyle -> {Directive[RGBColor[0.8, 0, 0] , Opacity[.5]], 
 Directive[RGBColor[0., 0.8, 0] , Opacity[.5]]}, 
ChartLabels -> {"1", "", "", "", "5", "", "", "", "", "10", "", "", 
  "", "", "15", "", "", "", "19"}, Frame -> True, 
 FrameLabel -> {"i", 
  "\!\(\*SubscriptBox[OverscriptBox[\(f\), \(_\)], \(n, i\)]\)"}, 
FrameStyle -> Thickness[.003], 
LabelStyle -> Directive[Black, Bold, Medium], 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 40, 
  FontFamily -> "Calibri"}, 
 ChartLegends -> Placed[{"Selection"}, {0.5, 0.9}]]

I want to compare the two data list5 and list4 and show in chart side by side.

$\endgroup$
7
  • 1
    $\begingroup$ When you say "side by side", do you have this in mind? PairedBarChart[list4, list5] . What do you mean by " ... and compare them": Do you have a metric for comparison? $\endgroup$
    – Syed
    Feb 2, 2022 at 12:10
  • $\begingroup$ list6 is the x axis which is same for both of them. So each value of list6 should have two bars side by side one correspond to list4 and other correspond to list5 which basically means i dont want both the bars to overlap each other whereas to come side by side $\endgroup$ Feb 2, 2022 at 12:22
  • 1
    $\begingroup$ Try: BarChart[Transpose[{list4, list5}]] and list6 is not evaluating. What is the value of n? And I am not sure why you have it twice (or at all). $\endgroup$
    – Syed
    Feb 2, 2022 at 12:27
  • $\begingroup$ Sorry, I have given the value of n, actually lists are generated from a complicated formulas. I forgot to mention the n. Thanks a lot for the transpose command. This is what I need but i would like to mark the x axis also $\endgroup$ Feb 2, 2022 at 12:30
  • $\begingroup$ How shall I write chart labels in the case of Transpose. And also how can I increase the width of the bar in the case of transpose $\endgroup$ Feb 2, 2022 at 12:31

1 Answer 1

6
$\begingroup$

Put labels at location 3 for your data:

data = Transpose[{list4, list5, IntegerString[Range[1, 19], 10, 2]}]

BarChart[Labeled[{#1, #2}, #3, Below] & @@@ data
 , Frame -> {{True, True}, {True, True}}
 , AspectRatio -> 4/10
 , FrameStyle -> Thickness[.001]
 , LabelStyle -> Directive[Black, Bold, Medium]
 , ChartStyle -> {Red, Blue}
 , BarSpacing -> {0, 0.3}
 , BaseStyle -> {
   FontWeight -> "Bold"
   , FontSize -> 40
   , FontFamily -> "Calibri"
   }
 , FrameTicks -> {{Automatic, None}, {None, None}}
 , ImageSize -> 800
 , GridLines -> Automatic
 , ChartLegends -> Placed[{"a", "b"}, {0.9, 0.9}]
 ]

enter image description here

You can experiment with spacings and styles to get the desired look.

$\endgroup$
4
  • $\begingroup$ Could you please also mention How shall I mark some points on the red bar. $\endgroup$ Feb 3, 2022 at 6:39
  • 1
    $\begingroup$ Try: Epilog -> { Text[Style["some text", Darker@Cyan, 12], {13, 0.5}] , Darker@Cyan , Arrowheads[0.02] , Arrow[{{12.6, 0.47}, {12.6, 0.24}}] } . By the way there are automatic Tooltip features activated for each data item. $\endgroup$
    – Syed
    Feb 3, 2022 at 7:41
  • $\begingroup$ Final querry. I want to mark these points on red bars The ticks does not seems to be unispaced. listst = {1.0526315786138172, 0.5555555541663151, 0.3921568573075441, 0.3124999796694264, 0.2666665956722264, 0.23809500179235274, 0.21977946619291758, 0.2083310131665477, 0.20201326465717925, 0.19997974697283805, 0.20196217882320022, 0.2081693710585961, 0.2193206639825469, 0.23680903638241013, 0.2630389206743215, 0.3020407644466671, 0.36053999654125235, 0.4497305815804302, 0.5879697753001203`}. $\endgroup$ Feb 3, 2022 at 9:03
  • $\begingroup$ You can start a separate question and provide a minimal working example of what you need. I think a barchart is a tool suited at best for crude visual comparisons only. $\endgroup$
    – Syed
    Feb 3, 2022 at 13:06

Your Answer

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

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