Hello, I would like to understand how I can mark highest and lowest value on the y-axis in a plot. Assume a simple plot
using Plots
x = 1:10; y = rand(10)
plot(x, y)
I will appreciate your guidance on, how
a. I can mark (dot or circle) and label the lowest and highest y-axis value
b. Give a custom name to the legend.
x = 1:10; y = rand(10)
maxpt = reverse(findmax(y)) # reversing so it's (x,y) rather than (y, x)
minpt = reverse(findmin(y))
plot(x, y)
scatter!([maxpt, minpt], label = "extrema")
More generally, findmax/findmin return (extremum, index). So if x didn’t conveniently go from 1-10, you would index into it with the appropriate index to make minpt/maxpt
Thank you! May I check a minor point with you? The label/legend sometimes overlap with the plot. Is there a way to align its position? I can’t see anything in the documentation.
Apologies, I have hit another problem. How can I add an external data point to the plot? For example, assume the plot is made using this code and I want to plot the data point (1.2,3) where x=1.2 and y =3