如何在MATLAB中制作一维图?

kol*_*vra 5 matlab plot

如何在MATLAB中制作如下图所示的图? 1D情节示例

我不需要标签,所以你可以忽略它们.我尝试使用普通的2D绘图,为每个数据点提供0到y的参数.它确实有帮助,但大多数情节仍然是空/白色,我不希望这样.在2d图中的1d图

我怎么解决这个问题?

编辑:

这是我的情节(玩ylim的值没有帮助):

hold on
for i=1:120
    if genders(v_labels(i)) == CLASS_WOMAN
        plot(v_images_lda(i,:) * w_lda,0,'r*');
    else
        plot(v_images_lda(i,:) * w_lda,0,'b.');
    end
end
title('LDA 1D Plot');
ylim([-0.2 0.2]);
hold off
Run Code Online (Sandbox Code Playgroud)

gno*_*ice 10

这样做的一个办法是调整'XLim','YLim'以及'DataAspectRatio'使之呈现为本质上是一个单行轴的特性.这是一个例子:

data1 = rand(1,20)./2;      %# Sample data set 1
data2 = 0.3+rand(1,20)./2;  %# Sample data set 2
hAxes = axes('NextPlot','add',...           %# Add subsequent plots to the axes,
             'DataAspectRatio',[1 1 1],...  %#   match the scaling of each axis,
             'XLim',[0 1],...               %#   set the x axis limit,
             'YLim',[0 eps],...             %#   set the y axis limit (tiny!),
             'Color','none');               %#   and don't use a background color
plot(data1,0,'r*','MarkerSize',10);  %# Plot data set 1
plot(data2,0,'b.','MarkerSize',10);  %# Plot data set 2
Run Code Online (Sandbox Code Playgroud)

你会得到以下情节:

在此输入图像描述


abc*_*bcd 5

这是使用dsxy2figxy和重现你的数字的一种方法annotate.dsxy2figxy可能很难找到第一次,因为它不是真的在你的道路上.它是MATLAB包的一部分,在示例函数中提供.您可以通过在帮助文档中搜索它来访问它,一旦找到它,打开它并将其保存到路径中的文件夹中.

h1=figure(1);clf
subplot(4,1,1);
hold on
xlim([0.2,1]);ylim([-1,1])

%arrow
[arrowX,arrowY]=dsxy2figxy([0.2,1],[0,0]);
annotation('arrow',arrowX,arrowY)

%crosses
x=[0.3,0.4,0.6,0.7,0.75];
plot(x,0,'kx','markersize',10)

%pipes
p=[0.5,0.65];
text(p,[0,0],'$$\vert$$','interpreter','latex')

%text
text([0.25,0.5,0.65],[1,-1,-1]/2,{'$$d_i$$','E[d]','$$\theta$$'},'interpreter','latex')

axis off
print('-depsc','arrowFigure')
Run Code Online (Sandbox Code Playgroud)

这将产生下图:

在此输入图像描述

这有点像一种hackish方式,因为我已经欺骗MATLAB打印一个子图.所有光栅化格式(jpeg,png,等)不会给你同样的结果,因为他们会全部打印整个数字包括在未宣布的次要情节应该去过.所以为了得到这个效果,它必须是一个eps,并且它可以使用它因为eps使用更紧密的边界框...所以所有无意义的空白被修剪.然后,您可以将其转换为您想要的任何其他格式.