How to make a graph with x-axis at top and data points relative to y-axis with a straight line joined scatter?

5 views (last 30 days)
Hi there, I am hoping to make a graph like this one picttures where there is a y-axis relation (not shown as this is a snip from a larger figure).
Thank you and apologies I am very new to the Matlab space!

Answers (1)

Cameron
Cameron on 12 Jan 2023
Edited: Cameron on 12 Jan 2023
You can do something like this
x = 1:10; %x data
y = x + round(rand(1,length(x)),2); %random y data
p = plot(x,y,'-o'); %plot
p.Parent.XAxisLocation = 'top'; %move the x axis to the top
p.Parent.YTick = []; %remove the y ticks
lbl = num2cell(y); %convert the number to a cell so it can be read using the text function below
text(x,y,lbl) %put the labels on the graph in the default location
You can also customize where you want the text location to be.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!