Mathematica:我可以将BarChart Legend与堆积的条形匹配吗? [英] Mathematica: Can I match the BarChart Legend to the stacked bars?

查看:163
本文介绍了Mathematica:我可以将BarChart Legend与堆积的条形匹配吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望堆叠条形图中的颜色垂直排列与图表图例中的颜色排列相匹配.但是,无论我尝试什么,它们都不匹配.这是情况

I would like to have the vertical arrangement of colors in stacked bars match the arrangement of colors in the chart legend. But no matter what I try, they don't match. Here's the situation

BarChart[{{5, 37, 56}, {22, 49, 28}, {31, 60, 10}},
   ChartLayout -> "Percentile",
   ChartLegends -> Placed[{"1-Volume", "2-Area", "3-Length"}, Right],
   ChartLabels -> {{"Before", "During", "After"}, None}]

在实际示例中,图例还有很多条目(6),因此,如果图例颜色的顺序与条形中的顺序匹配,那就很好了.我意识到我可以将ChartLegends设置为显示在Bottom上,但是考虑到许多图例条目,效果并不理想.

In the real-world example the legend has quite a few more entries (6), so it would be nice if the order of the legend colors matched the order in the bars. I realize that I could set the ChartLegends to display at Bottom, but doesn't look good given the many legend entries.

此外,反转图例"列表也无法正常工作.图例的文本已重新排序,但颜色未重新排序(请参见下文),因此图例标题不再与图表中的数据匹配.

Also, reversing the Legends list does not work as desired. The text of the legends was re-ordered, but the colors were not reordered (see below), so the legend captions no longer match the data in the chart.

更改数据(或数据和图例项)的顺序也不起作用.

Changing the order of the data (or the data and the legend items) does not work either.

有什么建议吗?

推荐答案

BarChart[{{5, 37, 56}, {22, 49, 28}, {31, 60, 10}}, 
  ChartLayout -> "Percentile", 
  ChartLegends -> {"1-Volume", "2-Area", "3-Length"}, 
  ChartLabels -> {{"Before", "During", "After"}, None}] /. 
 Column[List[a : Grid[List[___]] ..]] :> Column[Reverse@List@a]

修改

当您想弄乱Graphics/Chart/Plot内部时,请记住使用FullForm

Remember to use FullForm when you want to mess up with Graphics/Chart/Plot internals

这篇关于Mathematica:我可以将BarChart Legend与堆积的条形匹配吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆