简体   繁体   中英

matlab plot legend variable

My question is about the legend entry of a matlab plot.

I would like to have the input variables in the legend so that it looks like 'A_1 B_2'. A,1,B and 2 are input arguments in the variables letter1, number1, letter2, number2.

You can specify any names as inputs to the legend. Your question really seems to be about how to concatenate variables into a single string. Usually, the easiest way to do this is with the [] operators.

figure()
hold on
h1 = plot(1:10)
h2 = plot(5:15)
legend([letter1,'_',num2str(number1)],...
       [letter2,'_',num2str(number2)])

If it was the case, maybe you can just set it at the ending of the plot command and title, for instance:

g <- make_empty_graph() # crate a new canvas to show this example
plot(g) # just to pup up the canvas created

labeling:

legend("bottomleft", legend=c("legend1", "legend2", "legend"), lty=c(1,2,3), lwd=c(2.5,2.5,2.5), col=c("black", "burlywood4", "skyblue"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM