semilogx — Plot data with a logarithmic x-axis using MATLAB-compatible semilogx call patterns.
semilogx creates line plots like plot and configures the active axes to logarithmic scaling on X. It follows MATLAB-compatible argument forms, axes targeting, and handle behavior.
Syntax
h = semilogx(Y)
h = semilogx(X, Y)
h = semilogx(args...)Inputs
Y- Type
NumericArray- Required
- Yes
- Description
- Y data vector/matrix.
X- Type
NumericArray- Required
- Yes
- Description
- X data vector/matrix.
args- Type
Any- Required
- Variadic
- Description
- Plot-style inputs: optional axes handle, style tokens, and Name/Value pairs.
Returns
h- Type
NumericScalar- Description
- Line handle.
Errors
RunMat:semilogx:PlotFailed- When
- Underlying plot rendering/parsing fails while building the semilog plot.
- Message
semilogx: plot operation failed
RunMat:semilogx:LogAxisFailed- When
- Applying logarithmic X-axis mode fails.
- Message
semilogx: failed to apply logarithmic axis mode
RunMat:plotting:TooManyOutputs- When
- More than one output is requested from a coordinate chart constructor.
- Message
plotting: too many output arguments
Behavior
The builtin returns the same kind of numeric line handle as plot.
Only the x-axis is switched to log scale; the y-axis remains linear.
Axes log-mode state is subplot-local, so semilogx on one subplot does not force every axes in the figure into log mode.
Positive x-values are the meaningful domain for a logarithmic axis, even though the plotted line object still preserves the original data handle semantics.
Rendering and residency
semilogx uses the shared plot rendering path and then marks the active axes as logarithmic on X.
Direct floating rendering precisions
single
double
Coordinate broadcasting
none
Runtime contract and boundaries
The result is a host graphics handle, not a numeric coordinate array. Coordinate parsing, native source storage, series expansion, style validation and graphics state use the existing plotting owners. Numeric handle aliases are resolved at Runtime, so static inference does not guess that a scalar coordinate denotes axes. The line, bar, barh and area constructors may return a row of handles; the other identities return the first created handle. More than one language output is rejected before chart work.
Single and double source data use their native storage where the chart has typed source properties; all eight integer classes use the declared identity-specific coordinate/control rules. Rendering is an explicit floating geometry boundary. In particular errorbar, bar, barh and area convert client graphics data to floating geometry; this does not certify exact integer-valued rendered pixels. Complex, logical, sparse, empty and matrix admission is decided by each existing numerical/shape parser, not by this shared ingress. Unsupported representations raise the existing parser diagnostic rather than being assumed fully MATLAB compatible.
Direct GPU rendering is conditional on the actual owning provider, live physical input leases, floating class/storage, supported shape/style, compatible shared device exports and native plotting feature availability. A pre-effect unavailable direct route may take the existing client path; a failed or partially completed export/reduction/emission is terminal and never permission to replay on the host. Source-property reads and figure persistence can perform later explicit readback. There is no elementwise/reduction fusion, distributed execution or portable numeric provider kernel for these graphics sinks.
User-interface capability and host-callback effects describe graphics creation/presentation, not numeric purity. Portable Runtime linking and an ordinary execution stack allow Native and Wasm ingress; actual presentation requires the installed graphics host. Retained chart data, style metadata, renderer buffers and serialization are separate lifetimes. Current chart scratch/state has no complete finite allocation owner: Managed policy is rejected before argument extraction, gather or chart mutation through the existing HostAllocationReceipt authority. Ordinary Unbounded resident and host routes remain available. Issuer/policy/cancellation are fenced before publication and errors carry Never replay. This refusal, unbounded host loops, provider/renderer-private allocations, full property parity and measured performance remain open obligations; Incomplete/Partial is not a completion certificate.
Supported representations and remaining forms
Coordinates use real single/double Tensor storage or native integer storage. Scalar logical coordinates pass through the existing NumericInput double conversion; logical arrays, complex arrays, sparse arrays, categorical and datetime coordinate objects do not have a NumericInput representation and are not implemented by this chart owner.
Y-only calls, explicit X/Y pairs, repeated series, optional leading axes, LineSpec and shared line name/value controls delegate to the canonical plot owner with the actual RuntimeContext. Implicit indices are one-based doubles. Scalar numeric Y is normalized by NumericInput; empty Y produces matching empty coordinates. Host matrix expansion preserves native single/double/integer class and exact selected values, with no whole-matrix materialization per selected row or column. Log scaling changes display coordinates, not the source properties. Nonpositive values break logarithmic rendered segments rather than changing stored coordinates.
The owning call explicitly sets X logarithmic and Y linear on its selected subplot axes after plotting succeeds. It does not silently log-transform or overwrite XData/YData.
Examples
Plot a frequency response with a logarithmic x-axis
f = logspace(0, 4, 200);
mag = 1 ./ sqrt(1 + (f / 200).^2);
semilogx(f, mag);Compare two responses on the same semilog x-axis
f = logspace(0, 4, 200);
h1 = semilogx(f, 1 ./ sqrt(1 + (f / 200).^2));
set(h1, 'DisplayName', 'low-pass');
hold on;
h2 = semilogx(f, (f / 200) ./ sqrt(1 + (f / 200).^2));
set(h2, 'DisplayName', 'high-pass');
legend;Verify the x-axis scale through handle/property workflows
f = logspace(1, 3, 50);
semilogx(f, log10(f));
ax = gca;
get(ax, 'XScale')Expected output:
ans =
'log'Rendered semilogx example
frequency = logspace(0, 5, 400);
cutoff = 750;
gain_db = 20*log10(1 ./ sqrt(1 + (frequency/cutoff).^4));
h = semilogx(frequency, gain_db);
set(h, 'LineWidth', 2);
title('Low-Pass Frequency Response');
xlabel('Frequency (Hz)');
ylabel('Gain (dB)');
grid on;
Compare this result with other chart types in the plot examples.
Using semilogx with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how semilogx changes the result.
Run a small semilogx example, explain the result, then change one input and compare the output.
FAQ
When should I use semilogx instead of plot?⌄
Use semilogx when your x-data spans several orders of magnitude and you care about relative differences across that range. Frequency response curves (Bode magnitude plots) are the classic example — frequencies from 1 Hz to 100 kHz are unreadable on a linear axis but spread evenly on a log scale.
How is semilogx different from calling plot and then switching the x-axis to log?⌄
Functionally identical. semilogx(x, y) is shorthand for plot(x, y) followed by set(gca, 'XScale', 'log'). The convenience form just does both in one call and makes intent clearer when reading code.
What happens if my x-data contains zero or negative values?⌄
Logarithmic axes only render positive values. Zero and negative x-values are silently excluded from the rendered line — the data handle still holds them, but they won't appear on the plot. Filter your data to the positive domain if you need a continuous curve.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · autumn · axes · barh · bone · caxis · cla · clf · clim · colorcube · colororder · cool · copper · copyobj · cylinder · daspect · datacursormode · dataTipTextRow · drawnow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · gray · groot · hgload · hgsave · hidden · histogram2 · hold · hot · inferno · isgraphics · ishandle · jet · line · lines · linkaxes · magma · openfig · opengl · pan · parula · patch · pink · plasma · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · spring · stackedplot · subtitle · summer · suptitle · text · textscatter · textscatter3 · triplot · turbo · viridis · waitbar · winter · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
More plotting resources
Source you can read
Every RunMat function's source is public. Read exactly how semilogx is executed, line by line, in Rust.
- View the source for semilogx in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.