How To Put String Labels on Contours for Contour Plots in MATLAB

后端 未结 1 1875
终归单人心
终归单人心 2021-01-05 18:44

I am wondering if it is possible to label the contours of a MATLAB contour plot with a set of user-defined strings?

I am currently using the following code snipper t

相关标签:
1条回答
  • 2021-01-05 19:12

    In this case, hcl is actually an array which stores handles to every contour label on your plot. When you set properties using the array (as in your code),

    set(hcl, 'name', 'value')
    

    You will set the property of every label to the same value.

    You can change the properties of individual labels by iterating over the array. For example, this is how you would add a percentage sign:

    for i = 1:length(hcl)
        oldLabelText = get(hcl(i), 'String');
        percentage = str2double(oldLabelText)*100;
        newLabelText = [num2str(percentage) ' %'];
        set(hcl(i), 'String', newLabelText);
    end
    
    0 讨论(0)
提交回复
热议问题