Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

text is hidden behind markers, what now...

Asked by Jos on 11 May 2013

Somehow, my text labels are obscured by my large plot markers, like this

text(0.5, 0.5, 'I''m hidden', 'HorizontalAlignment', 'center');
plot(0.5, 0.5, '.r', 'MarkerSize', 100)

In this example, when I change the order between the text and plot commands (so first plot and then text, it's fine, it works). But somehow in my big cloudy figure, changing the order doesn't work.

Does anybody know how I can put the labels on the big markers, instead of behind?


Walter Roberson on 11 May 2013

Your "big cloudy figure" -- is that a line plot? Or is it a surf or patch or pcolor ?

Image Analyst on 11 May 2013

A screenshot would help. When your plot is up (and is the active window), type alt-printscreen to copy the window into the clipboard. Then go to and type control-v to paste it onto the website. Then tell us the URL it gives you. Or put a blank line, then a line with your url in between double < and > symbols to display the image right here.

Jos on 14 May 2013

Thanks for helping. I copied the figure to

The plot consists of a series of fill commands for the triangles, plot commands for the points along the circle (with different markersizes) and text commands for the numbers. The bigger markers obscure the text labels.



No products are associated with this question.

2 Answers

Answer by Sulimon Sattari on 15 May 2013

This is not the ideal answer, I am sure there's something cleaner but it works. The ordering of the axes children is the issue here.

Try this:

ax = gca;
axes_children = get(ax, 'Children') %the ordering of the array x determines what comes up on top. you want to re-arrange this array, and then re-set the children.
new_axes_children(1) = axes_children(2);
new_axes_children(2) = axes_children(1); %create a new array with the ordering flipped
set(ax, 'Children', new_axes_children);

If I think of something cleaner I'll comment again

1 Comment

Jos on 16 May 2013

Thanks, this works on the simple piece of code in the question. But for my figure something strange happens. In this figure, I use a fill command with transparency. And after this all markers are again on top of the text labels.

I thinks this code below demonstrates the problem:

text(0.5, 0.5, 'I''m hidden', 'HorizontalAlignment', 'center');
plot(0.5, 0.5, '.r', 'MarkerSize', 100)
ax = gca;
axes_children = get(ax, 'Children');
new_axes_children(1) = axes_children(2);
new_axes_children(2) = axes_children(1);
set(ax, 'Children', new_axes_children);
fill([0.5 2 3], [0.5 2 2], 'b');
fill([0.5 2 3], [0.5 2 2], 'b', 'FaceAlpha', 0.4);
Sulimon Sattari
Answer by Jan Simon on 16 May 2013

Alpha-blending means, that the OpenGL renderer is used. But then the implementation of the text rendering depends on your OpenGL driver and there is no general solution anymore. Sometimes it helps to define the text() with 3 coordinates and care for moving it between the camera and the objects - but this is not trivial when the camera is moved or the view angle is changed etc.

Sometimes it helps to change the EraseMode of the text from 'normal' to 'none'. But this can have surprising other effects, e.g. printing a hardcopy can let Matlab crash.


Jan Simon

Contact us