Text overlapp in uifigure plot
Mostrar comentarios más antiguos
Hi
I'm using text to plot the text in a user interface figure (x,y,str). I was unable to see the original text message since they overlapped.
Can someone please tell me how to prevent the words from overlapping?
Thank you!

19 comentarios
Adam Danz
el 10 de Jun. de 2020
Could you show us how you're plotting the text? It would be helpful if you could isolate the section of code that plots the text and explain it rather than sharing a bunch of code that isn't related to the text.
Life is Wonderful
el 10 de Jun. de 2020
Adam Danz
el 10 de Jun. de 2020
It looks like you're plotting the text in the same position in two different lines. Of course it will overlap.
Are you familiar with the text() inputs? If not, check out the documentation.
Life is Wonderful
el 11 de Jun. de 2020
Editada: Life is Wonderful
el 11 de Jun. de 2020
Adam Danz
el 11 de Jun. de 2020
Check out how the text function works. The first two inputs set the location of the text.
In your examples, you need to add hold on within each of the if/else-if blocks.
Going back to the original questions, I'm really lost about,
- What the final result should look like
- What the text inputs look like;
- How you want to position the text
It would be clearer if you could somehow illustrate what the final result should look like and what your inputs look like.
Life is Wonderful
el 11 de Jun. de 2020
Editada: Life is Wonderful
el 12 de Jun. de 2020
Life is Wonderful
el 11 de Jun. de 2020
Editada: Life is Wonderful
el 12 de Jun. de 2020
Life is Wonderful
el 11 de Jun. de 2020
Editada: Life is Wonderful
el 12 de Jun. de 2020
Adam Danz
el 11 de Jun. de 2020
I'm still very lost.
I don't have a mental image of what text you want to plot and where the text should go in the figure.
I dont' understand why you're plotting text at certain locations in the plot.
I don't understand what parts of the text should be included on the plot.
I don't understand what determines the (x,y) coordinates of the text.
If you can reduce the problem to a very small example (just a few lines of code) that demonstrates the inputs and the expected outputs for a few samples of text (2-3) it might be helpful.
Spend some time reading about the text() function in the documentation and going through the examples. That might be a much faster path toward a solution than trying to explain the problem a few times and waiting for a response.
Life is Wonderful
el 12 de Jun. de 2020
Editada: Life is Wonderful
el 12 de Jun. de 2020
Life is Wonderful
el 12 de Jun. de 2020
Editada: Life is Wonderful
el 12 de Jun. de 2020
Adam Danz
el 12 de Jun. de 2020
1) I'm not sure what I'm supposed to do with the app.
2) "The text('position',[]) - is not used. This is an issue for now." -- I don't understand this. text() is a function and the (x,y) position inputs are required. So I don't know what it means that the text position is not used.
3) "I want to plot , Time vs Message." I understand that time is along the x axis but what are the units of "message" along the y axis?
4) "I will take time to understand text() function " I think it may take an hour or two. But keep in mind this discussion has continued for ~2 days so reading through the documentation and truely understanding the inputs to the text() function will be faster.
I'd really like to help but the problem is still unclear.
Check out this example below and tell me if it's helpful or related to what you want to do.
fig = figure();
ax = axes(fig);
textSamples = {'First Row', 'Second Row', 'Third Row'};
x = 1:3
y = 1:3;
plot(ax, x, y, 'bo')
hold(ax, 'on')
% Example of text()
text(ax, x+.05, y, textSamples,'HorizontalAlignment', 'Left')
xlim([0,4])
ylim([0,4])
% example of labelpoints()
labelpoints(x,y,textSamples,'N','color','b') % N is for North

Life is Wonderful
el 12 de Jun. de 2020
Editada: Life is Wonderful
el 12 de Jun. de 2020
Adam Danz
el 12 de Jun. de 2020
Are you talking about the Horizontal and Vertical Alignment properties?
figure()
axes()
xlim([-1 1])
ylim([-1 1])
hold on
plot(0,0,'rx')
text(0, 0, 'A', 'HorizontalAlignment', 'Left', 'VerticalAlignment', 'Middle')
text(0, 0, 'B', 'HorizontalAlignment', 'Right', 'VerticalAlignment', 'Middle')
text(0, 0, 'C', 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Top')
text(0, 0, 'D', 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Bottom')

Life is Wonderful
el 12 de Jun. de 2020
Life is Wonderful
el 12 de Jun. de 2020
Adam Danz
el 12 de Jun. de 2020
Ah... good.
Note that you can also do the same thing with
labelpoints(0, 0, 'A', 'E') % For east
labelpoints(0, 0, 'B', 'W') % for west
labelpoints(0, 0, 'C', 'S') % For south
labelpoints(0, 0, 'D', 'N') % For north
% Also NE NW SE SW and C for center
In addition, you can offset the label from the coordinate by using
labelpoints(0, 0, 'D', 'N', 0.1) % where 0.1 is an offset factor
Life is Wonderful
el 12 de Jun. de 2020
Adam Danz
el 12 de Jun. de 2020
That's because this discussion has been in the comments section. I just added an answer that summarizes the solution.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Labels and Annotations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




