将图例添加到Mathematica中的半对数图

时间:2012-03-29 21:58:47

标签: wolfram-mathematica plot legend

我在使用Mathematica中的绘图功能时遇到了问题。 我试图在semilog图上绘制几个数据列表,然后添加一个图例。情节很好:

enter image description here

Show[ListLogPlot[bead31, PlotStyle -> Black, 
  PlotMarkers -> {"\[FilledSmallSquare]"}], 
 ListLogPlot[bead27, PlotStyle -> Blue, 
  PlotMarkers -> {"\[FilledSmallSquare]"}], 
 ListLogPlot[A5, PlotStyle -> Red, 
  PlotMarkers -> {"\[FilledSmallSquare]"}], 
 ListLogPlot[A10, PlotStyle -> Green, 
  PlotMarkers -> {"\[FilledSmallSquare]"}], 
 ListLogPlot[A20, PlotStyle -> Gray, 
  PlotMarkers -> {"\[FilledSmallSquare]"}], Frame -> True, 
 FrameLabel -> {Subscript[t, norm], \[Kappa]}, RotateLabel -> False, 
 PlotRange -> Automatic]

然而,任何添加图例的尝试都会失败,或者以相同的比例放置 - 而且由于它是一个semilog图,所以我看到的只是一个传奇线。

我尝试将图例分别创建为Graphics对象:

enter image description here

但是我无法弄清楚如何将它放在图像中(我正在使用Inset []和Epilog [],但我认为我使用它们是错误的)。

Show[Graphics[
  Legend[{{Graphics[{Black, Rectangle[{-1, -1}, {1, 1}]}], 
     "31 beads"}, {Graphics[{Blue, Rectangle[{-1, -1}, {1, 1}]}], 
     "27 beads"},
    {Graphics[{Red, Rectangle[{-1, -1}, {1, 1}]}], "A5"},
    {Graphics[{Green, Rectangle[{-1, -1}, {1, 1}]}], "A10"},
    {Graphics[{Gray, Rectangle[{-1, -1}, {1, 1}]}], "A20"}}]]]

如果有人知道如何将图例正确添加到第一张图表中,那么我们将非常感谢您提供帮助。

1 个答案:

答案 0 :(得分:3)

也许:

Needs["PlotLegends`"];
ListLogPlot[{
  Table[PartitionsQ[n], {n, 50}], 
  Table[{n, n!}, {n, 1, 20, .1}]}, 
    PlotLegend -> {"Parts", "Fact"}, LegendPosition -> {0.8, -0.8}]

enter image description here

相关问题