Matlab graph plotting - Legend and curves with labels

余生颓废 提交于 2019-12-08 00:39:04

问题


How to plot a figure like the one given below?

Here the legend (green/blue) is plotted with some values (0.10 to 0.40) on each curve. Is there any possible solution or hints to do this?

Figure Reference:


回答1:


Plotting data labels within lines is possible with clabel (contour labels), although this requires that you to plot your data with the contour command.

Although if you can't plot it as a contour plot then you should be able to convert your plot data to a contour matrix format, see the matrix definition at the bottom of the help page on the contour algorithm. This is a simple 2 row vector defining your data points, you should be able to feed this matrix into the clabel function to print the data labels inline.

For the example below - I plotted the 3 lines using the plot command, saving the line handles in the array h. I then created a contour matrix from the plotted data, so for example if the red line had 50 data points then

C(1,1)=0.44; % data value to plot on the line
C(2,1)=50; % number of data points
C(1,2:51)=line1x; % x data points for the red line
C(2,2:51)=line1y; % y data points for the red line

I did it manually to test the idea but I'm sure you could write a simple function to create this matrix automatically from your data if required. Anyway repeat adding the other line data to the contour matrix then use the contour label command

clabel(C,h)

Which gives me this plot



来源:https://stackoverflow.com/questions/19319455/matlab-graph-plotting-legend-and-curves-with-labels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!