【问题标题】:Interactively change color of data point in Matlab plot在 Matlab 图中以交互方式更改数据点的颜色
【发布时间】:2012-07-11 18:18:22
【问题描述】:

我正在研究 Matlab Plot。我有两个问题。

1) 绘图后,当用户选择数据点时,该数据点的颜色应该改变

2) 我需要获取该数据点的 x 和 y 值

有什么想法吗?

【问题讨论】:

    标签: matlab colors plot mouse


    【解决方案1】:

    使用工具栏中的Data Cursor

    【讨论】:

    • 如何使用数据光标改变标记的颜色
    【解决方案2】:

    对于第一种情况来获取用户输入,您可以尝试ginput 而对于第二种情况,如果您要显示图像,请使用imtool。它将向您显示像素位置和像素值。

    【讨论】:

      【解决方案3】:

      这个问题已有 4 年历史了,但完整的答案可能对某人有所帮助,所以就在这里......

      绘制您的数据:

      plot(rand(5,1),'.b','MarkerSize',40) % Large blue dots just to make it clear
      hold on
      

      创建一个数据游标对象:

      dcm_obj = datacursormode(gcf);
      

      为数据游标设置自定义更新函数:

      set(dcm_obj,'UpdateFcn',@dcfun)
      

      然后定义函数:

      function txt = dcfun(~,event_obj)
      pos = event_obj.Position;
      delete(findall(gcf,'Tag','DEL'))
      plot(gca,pos(1),pos(2),'.r','Markersize',40,'Tag','DEL')
      txt = cell(2,1);
      txt{1} = ['x: ',num2str(pos(1))];
      txt{2} = ['y: ',num2str(pos(2))];
      

      现在只需单击工具栏中的数据光标工具,然后单击一个数据点。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-31
        • 1970-01-01
        • 2020-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多