Mathematica Asked on July 8, 2021
If I have an example plotted data such as:
ListPlot[{{-20, 2}, {-10, 1}, {10, 0.001}, {20, 0.0000001}, {80, 0.000000001}}, PlotRange -> {{-20, 80}, All}]
Which plotted gives:
How can I use PlotRange
to display the x-axis every 10 units rather than every 20 units as it is by default?
Here I use the undocumented Charting`ScaledTicks
function:
ListPlot[
{{-20, 2}, {-10, 1}, {10, 0.001}, {20, 0.0000001}, {80, 0.000000001}},
PlotRange -> {{-20, 80}, All},
Ticks -> {
Charting`ScaledTicks[{Identity, Identity}][-20, 80, {10, 2}],
Automatic}
]
What I know about this function I've mostly learned in the comments to this answer. In short:
Charting`ScaledTicks[{scalingFunction, inverseScalingFunction}][min, max, divisions]
where divisions
can be a number, or {maximum number of major ticks, number of divisions between each pair of major ticks}
, so the specification I used above asks for labeled major ticks every 10 units, with one minor tick in between each major one (i.e., two divisions between each major tick). Note that sometimes the behavior of divisions is quirky; I assume that it uses FindDivisions
or similar behind the scenes, which always attempts to find "pretty" / "good" divisions according to a heuristic.
Correct answer by MarcoB on July 8, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP