Too many markers!

18 ビュー (過去 30 日間)
Ralf
Ralf 2011 年 2 月 28 日
コメント済み: Ioannis Filippidis 2016 年 1 月 26 日
Hello!
I have the following problem: I want to plot a curve with line and marker, but the data I want to plot are so many, that the markers end up as an very thick line.
How can I solve that? My first idea was to plot the curve twice: one time the line with all data points and a second curve consisting of less points only with the markers. But then I have the problem, that MATLAB handles the two curves in the legend separately.
I think it is a problem a lot of people have, but I have not found a solution yet.
Thanks already in advance.
Ralf

採用された回答

Ioannis Filippidis
Ioannis Filippidis 2013 年 2 月 17 日
In order to avoid having to keep track of all handles, there is a simple alternative.
You can use the 'HandelVisibility' argument when calling plot, in order to automatically hide the extra lines/markers from the legend. This way you can have a common replacement called plot_fewer_markers (I have actually implemented this and I'm going to upload it to file exchange when I find time, together with some other useful things), which then plots 3 times: once with a visible handle, only the first point, using the complete style you specified (e.g. 'r--o'), once more only the line with all points (or subsampled, but that's another story) with the style 'r--' and invisible handle, and one last time the markers, using fewer points with style 'ro' and again invisible handle.
In this way you can still continue working as usual and just call this function, the result will be as desired.
  2 件のコメント
Massimo Ciacci
Massimo Ciacci 2013 年 7 月 9 日
I just made a submission based on your suggestion to matlab central, called "line_fewer_markers". Very good trick indeed! P.S.: I mentioned your name too in the submission.
Ioannis Filippidis
Ioannis Filippidis 2016 年 1 月 26 日
Thanks for the attribution. For posterity, the function that I mentioned is at: https://github.com/johnyf/plot_utils/blob/bd304279ee0e000f72fc936e0ef9f3a690d4e654/plot_subsample/plot_fewer_markers.m

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 2 月 28 日
Plotting twice is the only effective way. You might choose to use scatter() to plot the markers instead of having Matlab draw the line twice.
To keep Matlab from including the same logical line twice in the legend, record the handles of what you do want plotted, and pass those handles as the first argument to legend()

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by