I would like to create plot similiar to this:
where significands are on y-axis, while $ \times 10^{4} $ is above the plot (or could be placed at any place in graph). So far I managed to get only exponent right, using this code:
f[x_] := 100 Exp[x] Sin[20 x];
ymax = 1.5*^4;
ymin = -1.5*^4;
xticks = {#, #} & /@ Range[0, 5, 0.5];
yticks =
Map[
{#, NumberForm[#, {3, 1}, ExponentFunction -> (4 &)]} &,
N[FindDivisions[{ymin, ymax}, 6]]];
Plot[f[x], {x, 0, 5},
PlotRange -> {{0, 5}, {ymin, ymax}},
Frame -> True,
FrameTicks -> {{yticks, None}, {xticks, None}},
Axes -> False]
I will be grateful for any help.
Answer
You can use the internal function Charting`ScaledTicks
to get the needed ticks:
plot = Plot[
f[x],
{x, 0, 5},
PlotRange->{{0,5}, {-15000,15000}},
Frame->True,
FrameTicks->{{Charting`ScaledTicks[{10^4#&, 10^-4#&}],None}, {Automatic,None}}
]
If you want to add $\times 10^{4}$ above the plot, you need to expand the padding. A good way to do this is to use my GraphicsInformation
function to obtain this information. Install with:
PacletInstall[
"GraphicsInformation",
"Site" -> "http://raw.githubusercontent.com/carlwoll/GraphicsInformation/master"
]
Then, load it:
<
The image padding is then:
pad = "ImagePadding" /. GraphicsInformation[plot]
{{23., 4.}, {17., 6.5}}
So, the final plot looks like:
Show[
plot,
Epilog -> Text[Row@{"\[Times] ", Superscript[10, 4]}, Offset[{0, 10}, Scaled[{0, 1}]], {-1, 0}],
PlotRangeClipping->False,
ImagePadding -> pad + {{0, 0}, {0, 14}}
]
Comments
Post a Comment