How can I show % values on the y axis of a plot?

风格不统一 提交于 2019-12-04 04:58:50

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

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

You could try fiddling with FrameTicks:

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

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

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!