2
$\begingroup$

I use this code

data = Table[{x, 6/x (Csc[30 x])^2}, {x, 1, 6}];
ListLogPlot[data, Joined -> True, Mesh -> All, Frame -> True, 
 FrameLabel -> {"x", "f"}]

and the result is

enter image description here

How can I ask Mathematica to start the $x$ axis from $1$, not $0$?

enter image description here

$\endgroup$
2
  • 3
    $\begingroup$ Add an option like PlotRange -> {{1, All}, Automatic}. And maybe PlotRangePadding -> {{Scaled[0.02`], Scaled[0.02`]}, {Scaled[0.02`], Scaled[0.05`]}} $\endgroup$
    – Michael E2
    Dec 6, 2020 at 14:59
  • 3
    $\begingroup$ data = Table[{x, 6/x (Csc[30 x])^2}, {x, 1, 6}]; ListLogPlot[data, Joined -> True, Mesh -> All, Frame -> True, FrameLabel -> {"x", "f"}, PlotRange -> All, PlotRangeClipping -> True, PlotRangePadding -> 0] $\endgroup$
    – cvgmt
    Dec 6, 2020 at 14:59

3 Answers 3

5
$\begingroup$

Perhaps the easiest way (in the sense that ListLogPlot figures out the plot range automatically) is just PlotRange -> All:

ListLogPlot[data, Joined -> True, Mesh -> All, Frame -> True, 
 FrameLabel -> {"x", "f"}, PlotRange -> All]

Another use case (see updated question) requires overriding the default Ticks:

data = Table[{x, 6/x (Csc[30 x])^2}, {x, 1, 5999}];
ListLogPlot[data, Joined -> True, Mesh -> All, Frame -> True, 
 FrameLabel -> {"x", "f"}, 
 FrameTicks -> {{Automatic, 
    Automatic}, {Charting`ScaledTicks[{Identity, 
         Identity}][##] /. {0., _, s__} :> {1., 1, s} &, 
    Charting`ScaledFrameTicks[{Identity, Identity}][##] /. {0., t_, 
        s__} :> {1., t, s} &}}, PlotRange -> All, 
 AxesOrigin -> {1, 0}]

This works with the first example, too.

$\endgroup$
7
  • $\begingroup$ @charmin Example? $\endgroup$
    – Michael E2
    Dec 6, 2020 at 23:53
  • $\begingroup$ @charmin That's from the plot range padding. Do you really want the first point on the left to land on the frame? But not the last point on the right? Usually a little space around the plot is desirable. (Consider {x, 1, 5999} and looks at both ends: Do you not want to see the 6000 tick mark?) $\endgroup$
    – Michael E2
    Dec 7, 2020 at 0:01
  • $\begingroup$ @charmin Do you want the 6000 to show if the last data point is 5999? $\endgroup$
    – Michael E2
    Dec 7, 2020 at 0:06
  • 1
    $\begingroup$ @charmin See update. $\endgroup$
    – Michael E2
    Dec 7, 2020 at 0:25
  • 1
    $\begingroup$ @charmin They're blue in my version, too. Tricky little devils, changing version to version. They've been around for a while. Search the sight. See update. I think the new edit works in both 12.0, 12.1.1 $\endgroup$
    – Michael E2
    Dec 7, 2020 at 0:58
4
$\begingroup$

Try PlotRange

ListLogPlot[data, Joined -> True, Mesh -> All, Frame -> True,FrameLabel -> {"x", "f"}, PlotRange -> {{1, Automatic}, Automatic}]

enter image description here

$\endgroup$
2
$\begingroup$

PlotRangePadding work.

data = Table[{x, 6/x (Csc[30 x])^2}, {x, 1, 6}]; ListLogPlot[data, 
 Joined -> True, Mesh -> All, Frame -> True, FrameLabel -> {"x", "f"},
  PlotRange -> All, PlotRangeClipping -> True, 
 PlotRangePadding -> 0.01]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.