How to display only y axis in plot

Hi, I haven’t been able to find out how to hide the x axis in a figure in octave. I only want to show the y-axis with its scale, but the x-axis line is still present, although I can hide the tick marks.

This is the example code:

clear, close all
x = linspace(0,1,1000)’;
y = 20-x.^2

figure;
plot(x,y,‘sk’,‘MarkerFaceColor’,‘k’,‘MarkerSize’,3);
axis([0;2;0.75min(y);1.25max(y)],“tic[y]”)
set(gca, “fontsize”, 20);
box off;

And this is the image:
image

axis(“off”) removes all axes, including y. And I cannot find a more specific option.

I cannot find how to do this. Eventually, if this can be solved, I would also be interested in knowing how to show/hide any axis, not just left and bottom.
something like tic[y-right] for example.

Thank you very much!

It doesn’t remove the x-axis. But you can make it merge with the background with set(gca, 'XColor', [1 1 1]).

1 Like

Hi, that is a good option. I still would like to be able to remove certain axes. Also which other properties besides XColor are available? The linewidth would be XLineWidth ?
Thanks!

Type doc "axes properties" in Octave or online.

Ok I was able to pull it off! Thank you very much!
This below is the result:

If anyone is interested in plotting orbital energy levels and occupations let me know. I can paste the whole code here, or upload it to Github

Cheers!

2 Likes

Glad it worked out! By all means, please post on Github and link from here. If anyone else needs to plot orbital energies they can find and use your code.

1 Like

A slightly better way to do this is set (gca, 'xcolor', 'none'). This will actually prevent the object (x-axis) from being drawn by the OpenGL renderer. The other way works, but will leave artifacts that can be selected if you export the figure (for example, print output.svg). It has the additional benefit of being immune to changes in the background color (which, I know, only very infrequently deviates from white).

Sample code:

plot (1:10, 'o-');
set (gca, 'xcolor', 'w')
set (gcf, 'color', 'm')
set (gcf, 'inverthardcopy', 'off')
print tst1.png
set (gca, 'xcolor', 'none')
print tst2.png

tst1.png with “XColor” = “white”

tst2.png with “XColor” = “none”