本文介绍了如何在图的y轴上显示%值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任何Mathematica图表或绘图中,如何在y轴上显示%值?

In any Mathematica chart or plot how can I show % values on the y axis?

我可能有这样的数据:

data = {{{2010, 8, 3}, 0.}, {{2010, 8, 31}, -0.052208}, {{2010, 9, 30},
  0.008221}, {{2010, 10, 29}, 0.133203}, {{2010, 11, 30},
  0.044557}, {{2010, 12, 31}, 0.164891}, {{2011, 1, 31},
  0.055141}, {{2011, 2, 28}, 0.114801}, {{2011, 3, 31},
  0.170501}, {{2011, 4, 29}, 0.347566}, {{2011, 5, 31},
  0.461358}, {{2011, 6, 30}, 0.244649}, {{2011, 7, 29},
  0.41939}, {{2011, 8, 31}, 0.589874}, {{2011, 9, 30},
  0.444151}, {{2011, 10, 31}, 0.549095}, {{2011, 11, 30}, 0.539669}};

DateListPlot@data

我只希望y轴的范围从0%到60%,而不是0.0到0.6.

I just want the y axis to range from 0% to 60% instead of 0.0 to 0.6.

推荐答案

使用FrameTicks -> {{left, right},{bottom, up}}

DateListPlot[data,
             FrameTicks -> {{{{0.0, "0%"}, {0.1, "10%"}, {0.2, "20%"},
                              {0.3, "30%"}, {0.4, "40%"}, {0.5, "50%"},
                              {0.6, "60%"}}, None},
                            {Automatic, None}}]

可以生成FrameTicks的表,例如

Table[{k/10., ToString@(10 k) <> "%"}, {k, 6}]
(* Out[10] := {{0.1, "10%"}, {0.2, "20%"}, {0.3, "30%"}, {0.4, "40%"}, {0.5, "50%"}, {0.6, "60%"}} *)

如果您需要进行大量计算,可以使用 LevelScheme ,该软件包可在Mathematica中生成良好的绘图要容易得多,尤其是在刻度线方面.

If you need to make a lot of figures there is LevelScheme, a free package that makes producing good plots in Mathematica much easier, especially when it comes to tick marks.

根据Jagra的建议,此处是一个函数,该函数根据数据集和所需的刻度步长创建刻度规格列表.假设数据结构始终相同.

As per Jagra's suggestion here is a function that makes a tick specification list based on the data set and with desired tick steps. Assumptions are that the data structure is the always the same.

ticks[step_, data_] := {{Table[{k, ToString@IntegerPart@(100 k) <> "%"},
                               {k,
                                Floor[Min@data[[All, 2]], step],
                                Ceiling[Max@data[[All, 2]], step],
                                step}], None},
                         {Automatic, None}};

现在您可以定义绘图功能

Now you can define a plotting function

plot = DateListPlot[#, FrameTicks -> ticks[.1, #]] &

并像这样使用它plot@data

最后,由于您的问题指定了 any Mathematica图,请记住FrameTicks仅适用于框架图,其他图则使用Ticks -> {{x ticks},{y ticks}}.

Finally, since your question specifies any Mathematica plot, remember that FrameTicks works only on framed plots, for other plots use Ticks -> {{x ticks},{y ticks}}.

这篇关于如何在图的y轴上显示%值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 20:38