Matlab cdfplot:如何控制标记间距

发布于 2024-11-25 14:28:08 字数 214 浏览 0 评论 0原文

我有一个 Matlab 图形,我想在论文中使用。该图包含多个 cdf 图。 现在的问题是我无法使用标记,因为标记在图中变得非常密集。 如果我想让样本稀疏,我必须从 cdfplot 中删除一些样本,这将导致不同的 cdfplot 线。

如何在保持实际线条的同时添加足够的标记?

标记

I have a Matlab figure I want to use in a paper. This figure contains multiple cdfplots.
Now the problem is that I cannot use the markers because the become very dense in the plot.
If i want to make the samples sparse I have to drop some samples from the cdfplot which will result in a different cdfplot line.

How can I add enough markers while maintaining the actual line?

Marker

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

物价感观 2024-12-02 14:28:08

一种方法是按照 @ephsmith 的解决方案 (1) 从曲线中获取 XData/YData 属性并将其设置回来。这是一条曲线的示例。

y = evrnd(0,3,100,1); %# random data

%# original data
subplot(1,2,1)
h = cdfplot(y);
set(h,'Marker','*','MarkerSize',8,'MarkerEdgeColor','r','LineStyle','none')

%# reduced data
subplot(1,2,2)
h = cdfplot(y);
set(h,'Marker','*','MarkerSize',8,'MarkerEdgeColor','r','LineStyle','none')
xdata = get(h,'XData');
ydata = get(h,'YData');
set(h,'XData',xdata(1:5:end));
set(h,'YData',ydata(1:5:end));

另一种方法是使用 ECDF 函数单独计算经验 CDF,然后减少使用 PLOT 绘图之前的结果。

y = evrnd(0,3,100,1); %# random data
[f, x] = ecdf(y);

%# original data
subplot(1,2,1)
plot(x,f,'*')

%# reduced data
subplot(1,2,2)
plot(x(1:5:end),f(1:5:end),'r*')

结果
绘图输出

One method is to get XData/YData properties from your curves follow solution (1) from @ephsmith and set it back. Here is an example for one curve.

y = evrnd(0,3,100,1); %# random data

%# original data
subplot(1,2,1)
h = cdfplot(y);
set(h,'Marker','*','MarkerSize',8,'MarkerEdgeColor','r','LineStyle','none')

%# reduced data
subplot(1,2,2)
h = cdfplot(y);
set(h,'Marker','*','MarkerSize',8,'MarkerEdgeColor','r','LineStyle','none')
xdata = get(h,'XData');
ydata = get(h,'YData');
set(h,'XData',xdata(1:5:end));
set(h,'YData',ydata(1:5:end));

Another method is to calculate empirical CDF separately using ECDF function, then reduce the results before plotting with PLOT.

y = evrnd(0,3,100,1); %# random data
[f, x] = ecdf(y);

%# original data
subplot(1,2,1)
plot(x,f,'*')

%# reduced data
subplot(1,2,2)
plot(x(1:5:end),f(1:5:end),'r*')

Result
plot output

寒冷纷飞旳雪 2024-12-02 14:28:08

我知道考虑到 MATLAB 的内置函数(无论如何在统计工具箱中),这可能是不必要的,但它可能对无法访问该工具箱的其他查看者有用。

经验CMF(CDF)本质上是经验PMF的累积和。后者可以在 MATLAB 中通过 hist 函数实现。为了获得经验 PMF 的良好近似值,必须适当选择 bin 的数量。在下面的示例中,我假设 64 个 bin 对于您的数据来说已经足够了。

%# compute a histogram with 64 bins for the data points stored in y
[f,x]=hist(y,64);

%# convert the frequency points in f to proportions
f = f./sum(f);

%# compute the cumulative sum of the empirical PMF
cmf = cumsum(f);

现在您可以使用 yuk 给出的简化数据示例来选择要绘制的点数量。

I know this is potentially unnecessary given MATLAB's built-in functions (in the Statistics Toolbox anyway) but it may be of use to other viewers who do not have access to the toolbox.

The empirical CMF (CDF) is essentially the cumulative sum of the empirical PMF. The latter is attainable in MATLAB via the hist function. In order to get a nice approximation to the empirical PMF, the number of bins must be selected appropriately. In the following example, I assume that 64 bins is good enough for your data.

%# compute a histogram with 64 bins for the data points stored in y
[f,x]=hist(y,64);

%# convert the frequency points in f to proportions
f = f./sum(f);

%# compute the cumulative sum of the empirical PMF
cmf = cumsum(f);

Now you can choose how many points you'd like to plot by using the reduced data example given by yuk.

∞琼窗梦回ˉ 2024-12-02 14:28:08
n=20 ; % number of total data markers in the curve graph
M_n = round(linspace(1,numel(y),n)) ; % indices of markers
% plot the whole line, and markers for selected data points
plot(x,y,'b-',y(M_n),y(M_n),'rs')

很简单......

n=20 ; % number of total data markers in the curve graph
M_n = round(linspace(1,numel(y),n)) ; % indices of markers
% plot the whole line, and markers for selected data points
plot(x,y,'b-',y(M_n),y(M_n),'rs')

verry simple.....

寄意 2024-12-02 14:28:08

尝试减小标记大小。

x = rand(10000,1);
y = x + rand(10000,1);
plot(x,y,'b.','markersize',1);

try reducing the marker size.

x = rand(10000,1);
y = x + rand(10000,1);
plot(x,y,'b.','markersize',1);
月野兔 2024-12-02 14:28:08

出于发布目的,我倾向于使用图形窗口上的绘图工具。这允许您调整所有绘图参数并立即看到结果。

如果问题是您的数据点太多,您可以:

1)。使用数据的每第 n 个样本进行绘图。尝试找到一个能够产生您想要的外观的 n。
2)。我通常将曲线拟合到我的数据中,并在拟合图中添加一些稀疏放置的标记来区分曲线。

For publishing purposes I tend to use the plot tools on the figure window. This allow you to tweak all of the plot parameters and immediately see the result.

If the problem is that you have too many data points, you can:

1). Plot using every nth sample of the data. Experiment to find an n that results in the look you want.
2). I typically fit curves to my data and add a few sparsely placed markers to plots of the fits to differentiate the curves.

給妳壹絲溫柔 2024-12-02 14:28:08

老实说,出于发布目的,我总是发现选择不同的 'LineStyle ''LineWidth' 属性提供了更清晰的结果。这也比尝试对数据进行下采样要容易得多,对于使用 制作的图来说,这也容易得多CDFPLOT 我发现标记只是遮挡了线条的阶梯性质。

Honestly, for publishing purposes I have always found that choosing different 'LineStyle' or 'LineWidth' properties for the lines gives much cleaner results than using different markers. This would also be a lot easier than trying to downsample your data, and for plots made with CDFPLOT I find that markers simply occlude the stairstep nature of the lines.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文