Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wolfram mathematica Mathematica:我可以将条形图图例与堆叠的条形图匹配吗?_Wolfram Mathematica_Bar Chart_Mathematica 8 - Fatal编程技术网

Wolfram mathematica Mathematica:我可以将条形图图例与堆叠的条形图匹配吗?

Wolfram mathematica Mathematica:我可以将条形图图例与堆叠的条形图匹配吗?,wolfram-mathematica,bar-chart,mathematica-8,Wolfram Mathematica,Bar Chart,Mathematica 8,我想让堆叠条中的垂直颜色排列与图表图例中的颜色排列相匹配。但不管我怎么尝试,它们都不匹配。情况是这样的 BarChart[{{5, 37, 56}, {22, 49, 28}, {31, 60, 10}}, ChartLayout -> "Percentile", ChartLegends -> Placed[{"1-Volume", "2-Area", "3-Length"}, Right], ChartLabels -> {{"Before", "Duri

我想让堆叠条中的垂直颜色排列与图表图例中的颜色排列相匹配。但不管我怎么尝试,它们都不匹配。情况是这样的

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),因此如果图例颜色的顺序与条形图中的顺序相匹配就更好了。我意识到我可以将
图表图例
设置为显示在
底部
,但是由于图例条目太多,看起来不太好

此外,反转图例列表也不能按需要工作。图例的文本已重新排序,但颜色未重新排序(见下文),因此图例标题不再与图表中的数据匹配

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

有什么建议吗

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]

编辑


当你想搞乱图形/图表/绘图的内部结构时,记得使用
FullForm

建立在下面给出的漂亮答案的基础上,另一种方法是使用
Part

bc[[2,1,1,1]]= Reverse@bc[[2,1,1,1]];bc
这可以从
FullForm

Position[bc, #, Infinity]& /@ {Framed[___],
Column[___],List[___,"1-Volume",___]}
或者从这些中的任何一个,也许,和尝试和错误

虽然这不是问题的一部分,但是,可能会使用“小把戏”(请参阅)来进一步操纵图例

bc/.Labeled[g_,Framed[leg_],pos_]:>
Labeled[g,Framed[leg,FrameStyle->Orange,RoundingRadius->10,
Background->LightYellow],pos]
例如,给出了以下内容:

零件
也可用于移除图例周围的框架(参见问题) 但是他的方法更加通用

bc[[2]]=bc[[2,1]];bc
你可以用这个

SetOptions[Legending`GridLegend, 
  Legending`LegendContainer -> (Framed@MapAt[Reverse, #, {1, 1}] &)];

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

天哪。我从没想过要这么做。因此,您在发出
BarChart
命令后更改了图例的顺序?@David尝试以下
BarChart[..]//FullForm
并查看几乎在末尾的Column命令:)这非常有启发性。谢谢,干得好!我还没有意识到一个人可以深入到图表的内部。我的传奇看起来很大。我想我当时处于演示模式;它不会影响其他字体的字体大小。顺便说一句,很高兴把你推到2k以上。@David谢谢你。看看我对它的其他用途。