edit at the end
I encountered an interesting bug (?) when plotting where if a Gridline is outside the boundaries set by PlotRange, then the plot appears distorted and automatically resizes so that the full span of the image includes the 'invisible' gridline.
Here is a quick example where I plot two frequencies at 180 and 160 Hz, specify the PlotRange to only look at the desired range, but if I introduce a gridline at 300 Hz, which lies outside the visible range, it distorts.
nSamples = 2^14;
sRate = 2^14;
time = Array[# &, nSamples, {0, nSamples/sRate}];
x1 = Sin[2 \[Pi] 180 time]; \
(* generate the first frequency *)
x2 = Sin[2 \[Pi] 160 time]; \
(* generate the second frequency *)
x = (x1 + x2)/2;
fft = (Abs@
Fourier[x,
FourierParameters -> {-1,
1}])^2; (* generate power spectrum*)
fSpace = Table[(n - 1.) sRate/Length[fft], {n,
Length[fft]}]; (* create the frequency space *)
ListLinePlot[{fSpace, fft}\[Transpose],
PlotRange -> {{150, 210}, Full},
GridLines -> {{300}, None}] (* plot *)
For reference, this is how it looks like if the gridline is within the boundary (gridline at 180 rather than 300)
Does anyone know how can this be circumvented? I must note that in both cases the ImageSize is fixed.
EDIT: I'm using v.13.0 on Windows and the following options:
SetOptions[{ListPlot},
Frame -> {True, True, False, False}, ImageSize -> 350,
PlotStyle ->
Evaluate[{AbsolutePointSize[10], cols[[#]]} & /@
Range[Length@cols]], PlotRange -> Full,
FrameStyle -> Directive[Black, 14, AbsoluteThickness[2]]];
with "cols" being a list with RBG colours.