How can I rescale / format chart elements in a bar chart?

In this simple MWE, I create a simple chart element of a female figure, and then I apply it to a barchart, with the following code (note: womfig = this little stick figure here).

bd = BarChart[{0.76, 8.34},
ChartLabels -> {"With screening", "No screening"} ,
ChartElements -> {womfig, {1, 1}}, BarOrigin -> Left,
PlotLabel -> Style["Lifetime cervical cancer deaths
per 1000 women", FontSize -> 18], PlotRange -> Full,
ImageSize -> Large, BarSpacing -> 0]


This is a good start, producing this figure, but with a lot of wasted space:

I have been less successful in trying to eradicate the dead space unfortunately; when I try to truncate to just the bars of interest, it creates a unwanted space between the bars.

For example, if I add PlotRange -> {{-1.5, 8.5}, {0.5, 2}}, it makes things a lot worse. I imagine this has to do with rescaling of the chart elements when you adjust the plot region: but is there an easy way to produce something like the below?

I ask because eventually this will need to take varying values, so manual tweaking is a nuisance...

• Notice also that portion of last figure bigger than 0.34. That's also wrong. Similarly for bottom one. It should be 0.76 of figure not hole figure. Commented Jun 13, 2021 at 17:38
• That's an excellent point - weirdly, in an old mathematica notebook for an earlier release, it seemed to work fine and produced this (correct) output... imgur.com/7mcdxnR
– DRG
Commented Jun 13, 2021 at 17:45
• AxesOrigin -> {2, 0}, PlotRange -> {Automatic, {0, 2.5}} seems to solve both your problem and the problem @OkkesDulgerci mentioned. PlotLabel could be better positioned by wrapping the plot in a Labeled function. Tested in Mathematica 12.3 Commented Jun 13, 2021 at 17:53
• You may find this answer useful, DS 10814 Commented Jun 14, 2021 at 11:43

 womfig = Import["https://i.imgur.com/n6m1Rkc.png"];


1. You can use the (undocumented) option "FixedBarSpacing" to remove the extra space above and below the bars and use the spec {womfig, {1, All}} for ChartElements to have the figure stretch vertically to fill the bounding box of the bar:

 BarChart[{0.76, 8.34},
ChartLabels -> {"With screening", "No screening"},
ChartElements -> {womfig, {1, All}},
BarOrigin -> Left,
PlotLabel -> Style["Lifetime cervical cancer deaths\nper 1000 women", FontSize -> 18],
ImageSize -> Large,
"FixedBarSpacing" -> True,
BarSpacing -> 0]


Play with AspectRatio option values to get the desired proportion for vertical and horizontal lengths of bars. For example, add the option AspectRatio -> 1/4 to get:

2. Alternatively, use {{0.76, 8.34}} (instead of {0.76, 8.34}) as the first argument of BarChart with the option BarSpacing -> {0, 1} to get the same result:

BarChart[{{0.76, 8.34}},
ChartLabels -> {"With screening", "No screening"},
ChartElements -> {womfig, {1, All}},
BarOrigin -> Left,
PlotLabel -> Style["Lifetime cervical cancer deaths\nper 1000 women", FontSize -> 18],
ImageSize -> Large,
BarSpacing -> {0, 1},
AspectRatio -> 1/4]


• Fantastic, this is perfect - thank you!
– DRG
Commented Jun 13, 2021 at 20:05
• @DRG, my pleasure.
– kglr
Commented Jun 13, 2021 at 20:11

Seems to me that you want to play a bit with AspectRatio and the size of the womfig bar.

Just a start:

bd = BarChart[{0.76, 8.34},
ChartLabels -> {"With screening", "No screening"},
ChartElements -> {womfig, {1, 1}},
BarOrigin -> Left,
PlotLabel -> Style["Lifetime cervical cancer deaths
per 1000 women", FontSize -> 18],
PlotRange -> Full,
ImageSize -> Large, BarSpacing -> 0,
AspectRatio -> #] & /@ {1, 0.75, 0.5, 0.25}