How do I plot a set of data with a non-numerical X-axis using the workspace?

10 visualizaciones (últimos 30 días)
I need to plot batch data with viscosity at the y-axis and batch at the x-axis. I have all of the data in a worksheet, with 67 data points.
batch = export.Batch %naming the column as a variable 'batch'
plot(export.LO003201ViscosityBrookfield);
xticks(1:1:67)
xticklabels(batch)
plottools('on')
I would like to not label every single batch, but every 10 batches. The problem with the code above is that it plots every batch at the x-axis and if 'xticks' is changed from (1:10:67) it does goes in individual order of what is in the worksheet and does not skip the labeling from 1 to 10.

Respuestas (1)

Akanksha
Akanksha el 10 de Jun. de 2025
The problem with the provided code was a mismatch between the number of tick positions and the number of labels, especially when trying to label only every 10th batch. Here's simple code that will help you to get the desired plot:
% Load the data from the Excel file
export=readtable('worksheet.xlsx');
% Extract batch names and viscosity values
batch=export.Batch;
viscosity=export.Viscosity;
% Create the plot
figure;
plot(viscosity,'-o');
xlabel('Batch');
ylabel('Viscosity');
title('Viscosity vs Batch');
gridon;
% Set x-ticks to every 10th batch
xtickPositions=1:10:length(batch);
xticks(xtickPositions);
xticklabels(batch(xtickPositions));
% Rotate x-axis labels for better readability
xtickangle(45);
I have tried the above code with the dummy worksheet and got the following plot:
PFA the links for further reference :
Hope this helps!

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by