Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
In scientific research and computational data analysis, empirical variables frequently span several orders of magnitude. Standard linear axes compress lower-magnitude values into indistinguishable clusters while overemphasizing large values. A MATLAB log plot transforms one or both coordinate axes to a logarithmic scale (base-10), exposing power-law scaling, exponential kinetics, and wide-dynamic-range spectra clearly. Researchers can implement logarithmic plotting in MATLAB using dedicated functions—semilogx, semilogy, and loglog—or by altering axes scaling properties dynamically on existing figures.
What it is used for in research
Logarithmic transformations in MATLAB are essential across physical, engineering, biological, and economic research disciplines where phenomena operate over exponential or multiplicative scales:
- Exponential Growth and Decay Kinetics (semilogy): In chemical kinetics, microbial culture monitoring, pharmacology (pharmacokinetics elimination phases), and nuclear physics (radioactive half-life decay), quantities change at rates proportional to their current value. Plotting time on a linear horizontal axis and concentration on a logarithmic vertical axis linearizes the exponential relationship y(t) = y0ekt into a straight line with slope proportional to the rate constant k.
- Frequency Response and Sensor Calibration (semilogx): In acoustics, audio signal processing, and electrical network analysis, frequency ranges span decades (e.g., 20 Hz to 20 kHz). Visualizing frequency on a logarithmic horizontal axis alongside linear amplitude or phase measurements provides clear decade resolution without crowding the lower frequencies.
- Power-Law Distributions and Scaling Laws (loglog): When physical relationships adhere to power laws of the form y = axb—such as aerodynamic drag versus velocity, metabolic scaling across organism mass (Kleiber’s law), fractal dimensions, and network degree distributions—a matlab log-log plot produces a straight line whose visual slope directly represents the scaling exponent b.
- Comparative Dynamic Range: Research workflows involving MATLAB figure graphics and export workflows routinely require multi-decade comparisons where linear displays fail to resolve subtle features across lower-magnitude regimes.
How to install or access it
All logarithmic plotting routines in MATLAB (semilogx, semilogy, loglog, and xscale/yscale) belong to the core MATLAB graphics engine and do not require specialized add-on toolboxes.
- Official Portal: Access MATLAB installers and cloud environments exclusively through the official MathWorks portal at
mathworks.comusing an authorized institutional, organizational, or individual MathWorks Account. - Desktop Installation: Download the MathWorks Installer for your operating system (Linux x86-64, macOS Apple silicon/Intel, or Microsoft Windows). Logarithmic visualization capabilities are fully native from basic base installations.
- MATLAB Online: Run MATLAB directly in any modern web browser at
matlab.mathworks.comwithout local client installation. Figures render interactively using WebGL and client-side canvas acceleration. - Environment Verification: Confirm your active MATLAB release in the Command Window by executing:
ver('matlab')Table input support for plotting functions is standard in releases R2022a and newer.
Step-by-step instructions
Follow these step-by-step instructions to prepare empirical data, execute logarithmic plots, and customize axes for scientific publication.
- Validate and Filter Data Arrays:
Logarithms are undefined for zero and negative real numbers (log10(z) requires z > 0). Before plotting, verify that your data vectors contain only positive values. Use logical indexing to filter out non-positive entries:% Generate sample power-law data x_raw = [0, 0.5, 1, 2, 5, 10, 50, 100, 500]; y_raw = [-3, 0.12, 0.5, 1.8, 12, 45, 1100, 4200, 105000]; % Mask strictly positive pairs valid_idx = (x_raw > 0) & (y_raw > 0); x = x_raw(valid_idx); y = y_raw(valid_idx); - Select and Call the Appropriate Plotting Function:
Choose the function that matches your research variable scaling requirements:- Logarithmic X-Axis only:
figure('Name', 'Semilogx Example'); semilogx(x, y, '-o', 'LineWidth', 1.5, 'MarkerFaceColor', 'b'); - Logarithmic Y-Axis only: Ideal when combined with mathematical models for calculating exponential curves in MATLAB:
figure('Name', 'Semilogy Example'); semilogy(x, y, '-s', 'LineWidth', 1.5, 'Color', [0.85, 0.32, 0.1]); - Log-Log Scale (matlab log-log plot):
figure('Name', 'LogLog Example'); loglog(x, y, '-d', 'LineWidth', 1.5, 'MarkerSize', 6);
- Logarithmic X-Axis only:
- Enable Major and Minor Grid Lines:
Logarithmic plots require both major and minor grid lines to clearly delineate decade increments (e.g., 10, 20, 30 … 100):grid on; grid minor; - Configure Decade Ticks and Publication Labels:
Apply explicit tick marks and annotations using customizing plot labels and axis annotations in MATLAB:ax = gca; ax.FontSize = 11; ax.LineWidth = 1.0; ax.Box = 'on'; % Set explicit decade ticks ax.XTick = 10.^(-1:3); ax.YTick = 10.^(-1:5); xlabel('Reynolds Number, Re [-]', 'FontWeight', 'bold'); ylabel('Fanning Friction Factor, f [-]', 'FontWeight', 'bold'); title('Empirical Friction Scaling (Log-Log)', 'FontSize', 12); - Alternative: Convert an Existing Linear Plot to Logarithmic:
If you have already created a standard plot usingplot(x, y), convert the axes post-hoc without redrawing:plot(x, y, 'k-'); xscale('log'); % Modern syntax (or set(gca, 'XScale', 'log')) yscale('log'); % Modern syntax (or set(gca, 'YScale', 'log')) grid on; grid minor;
Output and how to read it
Interpreting a MATLAB log plot requires understanding how logarithmic compression alters visual slopes and spatial distance:
- Decade Spacing: On a base-10 logarithmic axis, the physical distance between 100 (1) and 101 (10) equals the distance between 101 (10) and 102 (100). Within any single decade, minor ticks (2, 3, 4, …, 9) compress progressively closer toward the subsequent decade boundary because log10(n+1) – log10(n) decreases as n increases.
- Reading Semilogy Exponential Slopes: A straight line on a
semilogyplot demonstrates pure exponential behavior:y = y_0 * exp(k * x) --> ln(y) = ln(y_0) + k * xThe rate constant k is extracted from the slope of
log(y)againstxusing:fit_params = polyfit(x, log(y), 1); growth_rate_k = fit_params(1); - Reading Log-Log Power-Law Exponents: In a matlab log-log plot, a linear visual trend confirms a power-law relationship:
y = a * x^b --> log10(y) = log10(a) + b * log10(x)The visual slope directly reflects the exponent b:
log_p = polyfit(log10(x), log10(y), 1); scaling_exponent_b = log_p(1); coefficient_a = 10^(log_p(2)); - Specialized Frequency Plots: In engineering dynamics and feedback design, logarithmic frequency axes are paired with decibel or phase axes, as demonstrated in Bode frequency response plots in MATLAB. When displaying experimental replicates with measurement dispersion, combine logarithmic axes with MATLAB error bar plots for statistical uncertainty.
Troubleshooting
| Symptom or MATLAB Message | Root Cause | Resolution |
|---|---|---|
Warning: Negative data ignored or Data with values <= 0 omitted |
Vector passed to semilogx, semilogy, or loglog contains values ≤ 0, which have no real logarithmic representation. |
Pre-filter arrays using logical indexing: valid = (x > 0) & (y > 0); semilogx(x(valid), y(valid));. If zero represents baseline offset, apply a scientifically justified baseline shift before plotting. |
| Axis limits collapse to identical values or plot displays blank canvas | Data vector has zero dynamic range (all values identical) or filtered down to zero elements. | Verify input array size using numel(x) and range via min(x) and max(x). Explicitly define axes bounds using xlim([x_min, x_max]) and ylim([y_min, y_max]). |
Minor grid lines missing despite calling grid minor |
Axis limits span less than one full decade or span more than roughly 8 decades, causing MATLAB to suppress minor grid lines to prevent visual clutter. | Check decade span. For narrow ranges, force explicit ticks: ax = gca; ax.YTick = [1, 2, 5, 10];. |
hold on resets log scale back to linear |
Subsequent call to standard plot() or high-level function resets axis scale properties when nextplot state is modified. |
After adding all series with hold on, explicitly reinforce logarithmic scaling: set(gca, 'XScale', 'log', 'YScale', 'log');. |
Free alternatives
Researchers seeking open-source computational tools can produce equivalent publication-quality logarithmic plots without commercial licenses:
| Software / Library | Logarithmic Plot Syntax | MATLAB Code Compatibility | License & Availability | Primary Research Fit |
|---|---|---|---|---|
| GNU Octave | semilogx(x,y)semilogy(x,y)loglog(x,y) |
High (drop-in script execution) | GNU GPLv3 (free and open-source) | Running existing MATLAB scripts, headless automated clusters, and open science reproducibility. |
| Python (Matplotlib) | plt.semilogx(x,y)plt.semilogy(x,y)plt.loglog(x,y)ax.set_xscale('log') |
Medium (procedural API patterns mirror MATLAB) | BSD-compatible (free and open-source) | Python scientific stack (NumPy, SciPy, pandas, JupyterLab) across bioinformatics, astronomy, and machine learning. |
| R (Base Graphics) | plot(x, y, log="x")plot(x, y, log="y")plot(x, y, log="xy") |
Low (argument-driven syntax) | GNU GPL (free and open-source) | Quick exploratory data analysis in biostatistics and experimental clinical research. |
| R (ggplot2) | scale_x_log10()scale_y_log10() |
Low (declarative Grammar of Graphics) | MIT License (free and open-source) | Complex multi-panel publication figures and genomic data visualization. |
| Julia (Plots.jl) | plot(x, y, xscale=:log10, yscale=:log10) |
Low (attribute-driven declarative) | MIT License (free and open-source) | High-performance differential equation simulation and numerical computing. |
FAQ
What is the difference between semilogx, semilogy, and loglog in MATLAB?
The difference lies in which coordinate axis is transformed to a logarithmic scale. semilogx applies a base-10 logarithmic scale to the horizontal x-axis while keeping the vertical y-axis linear. semilogy maintains a linear horizontal x-axis and applies a base-10 logarithmic scale to the vertical y-axis. loglog applies base-10 logarithmic scales to both the x-axis and y-axis simultaneously.
Can I plot zero or negative numbers on a MATLAB log plot?
No. Logarithms are mathematically undefined for zero and negative numbers in the real domain. When passed negative or zero values, MATLAB prints a warning message (Warning: Negative data ignored or Data with values <= 0 omitted) and silently drops those coordinates from the rendered graphics. You must clean your vectors with logical masks (e.g., x(x > 0)) before plotting.
How do I change an existing linear MATLAB plot to a logarithmic scale?
You do not need to regenerate the figure. In active MATLAB figures, call xscale('log') to set the horizontal axis to logarithmic, or yscale('log') for the vertical axis. Alternatively, modify axes properties directly via the current axes handle: ax = gca; ax.XScale = 'log'; ax.YScale = 'log';.
How do I display minor grid lines on a MATLAB log plot?
Enable the secondary grid by calling grid on; followed by grid minor;. MATLAB will automatically draw subdivision lines across each decade (representing 2×10k, 3×10k, …, 9×10k), allowing readers to quantitatively interpolate data values across orders of magnitude.
Sources
- MathWorks Help Center. (2026). semilogx: Semilogarithmic plot (logarithmic x-axis). MATLAB Documentation. Accessed 2026-11-11. https://www.mathworks.com/help/matlab/ref/semilogx.html
- MathWorks Help Center. (2026). semilogy: Semilogarithmic plot (logarithmic y-axis). MATLAB Documentation. Accessed 2026-11-11. https://www.mathworks.com/help/matlab/ref/semilogy.html
- MathWorks Help Center. (2026). loglog: Log-log scale plot. MATLAB Documentation. Accessed 2026-11-11. https://www.mathworks.com/help/matlab/ref/loglog.html
- MathWorks Help Center. (2026). Axes Properties: Control appearance and behavior of axes. MATLAB Graphics Documentation. Accessed 2026-11-11. https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html
- Free Software Foundation. (2026). GNU Octave: Two-Dimensional Plots. Manual Edition 9. Accessed 2026-11-11. https://docs.octave.org/latest/Two_002dDimensional-Plots.html







