如何在绘图的 y 轴上显示 % 值?

发布于 2024-12-19 11:45:48 字数 640 浏览 1 评论 0原文

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

我可能有这样的数据:

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。

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

I may have data like this:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天邊彩虹 2024-12-26 11:45:48

使用 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 中生成良好的绘图,尤其是在涉及刻度线时。

编辑:根据 Jagra 的建议,这里有一个函数,可以根据数据集和所需的刻度步骤制作刻度规范列表。假设数据结构始终相同。

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}}; 

现在您可以定义一个绘图函数

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

并像这样使用它 plot@data

最后,由于您的问题指定任何 Mathematica 图,请记住 FrameTicks 可以工作仅在框架图上,对于其他图,请使用 Ticks ->; {{x 个刻度},{y 个刻度}}

Use 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}}]

enter image description here

The table for FrameTicks can be generated, e.g.,

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%"}} *)

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.

EDIT: 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, #]] &

and use it like this plot@data

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}}.

捶死心动 2024-12-26 11:45:48

您可以尝试摆弄 FrameTicks

在此处输入图像描述

You could try fiddling with FrameTicks:

enter image description here

不打扰别人 2024-12-26 11:45:48

假设您的 y 轴值以比率形式给出,并且您希望它们以百分比形式给出,最简单的解决方案是:

DateListPlot[{#1, 100 #2} & @@@ data]

在此处输入图像描述

Assuming your y-axis values are given as ratios and you want them as percentages, the simplest solution is:

DateListPlot[{#1, 100 #2} & @@@ data]

enter image description here

浴红衣 2024-12-26 11:45:48

我没有看到图形选项,这种可能性,但您可以创建一个中间函数,将您的数字转换为右侧。您将显示该函数的图形。这很容易做到。
祝你好运!

I do not see the graphics options, such a possibility, but you can create an intermediate function that will convert your number to the right. You're going to display the graph of this function. This can be done easily.
Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文