How to make 1-D graphics in MATLAB?

How can I make graphs in MATLAB as shown below? 1D plot example

I don't need labels, so you can ignore them. I tried using a normal 2D plot by specifying a parameter from 0 to y for each data point. This helps, but most of the plot remains blank / white, and I don't want that.1d plot in 2d figure

How can I solve this problem?

Edit:

This is how I draw (playing with or does not help):

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
+5
source share
4 answers

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')

:

enter image description here

, MATLAB . (jpeg, png ..) , , , . , eps, , eps ... . .

+5

- '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

:

enter image description here

+10

, :

hax = gca();
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

set(hax, 'visible', 'off');
hax2 = axes();
set(hax2, 'color', 'none', 'ytick', [], 'ycolor', get(gcf, 'color');
pos = get(hax, 'position');
set(hax2, 'position', [pos(1), pos(2)+0.5*pos(4), pos(3), 0.5*pos(4)]);
title('LDA 1D Plot');

hold off

So, I hid the original axis and created a new one located on 0 of the original axis, and since I could not completely remove the y axis, I set its color to the background color of the figure. You can then decide whether you want to play with the x axis marks as well.

Hope this helps!

+3
source

A very naive trick, but useful.

Plot in 2d using the matlab plot function. Then, using the properties of the figure, compress it to any axis on which you need the 1st chart! Hope this helps :)

-1
source

All Articles