You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Text overlapp in uifigure plot
47 views (last 30 days)
Show older comments
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 Comments
Life is Wonderful
on 10 Jun 2020
Below is the code snippet performing the text plot.
c= app.UITable.Data;
s_DropDown1 = app.UITable.Data.(app.DropDown1.Value);
s_DropDown2 = app.UITable.Data.(app.DropDown2.Value);
range = (x);
h = duration([c{range,1}]);
hold(app.UIAxes,'on'); grid(app.UIAxes,'minor');
plot(app.UIAxes,h,range,"Color",rand(1,3));
set(0,'DefaultTextInterpreter','none');
hText1 = text(app.UIAxes,h,range,s_DropDown1(range),range,'VerticalAlignment','bottom',"FontSize",12, "Color",rand(1,3));
hText2 = text(app.UIAxes,h,range,s_DropDown2(range),range,'VerticalAlignment','bottom',"FontSize",12.5, "Color",rand(1,3));
Life is Wonderful
on 11 Jun 2020
Edited: Life is Wonderful
on 11 Jun 2020
Thanks Adam,
I am NOT clear, what is the meaning of position of Text. It can be
Case -1
||Time || Message
|00.00.00.001 | str1 str2 % Line 1 with Dropdown1 cell data & Dropdown2 CellData
Case -2
||Time || Message
|00.00.00.001 | str1 % Line 1
|00.00.00.001 | str2 % Line 2
How do i postion string in a designated postion ?
I want text print to be like Case -1/ since my text data is from same line and NOT next line but they are overlapped , I want the text overlap data (from each Dropdown menu) to be removed
Probably i can think of below example . Case 2 works better than other cases!
Can you please help me with better explanation for my implementation needs?
Thank you!
clc;close all;
x = [1:5] ;
y = [1:5] ;
bit_position = 2;
str1 = ['one '];
str2 = ['two '];
str3 = ['three'];
str4 = ['four '];
str5 = ['five '];
str = ['One',...
'Two',...
'Three',...
'Four',...
'Five'];
for i = 1:numel(x)
plot(x,y);
if isequal(bit_position,1)
subplot(3,1,1);
text(x(i),y(i),str(i), 'position',[i/numel(x) i/numel(x)]);
xlabel('xTicks');ylabel('MSG');
elseif isequal(bit_position,2)
subplot(3,1,2);
text(x(1),y(1),str1,'position',[1 10]);
text(x(2),y(2),str2,'position',[1 10]);
text(x(3),y(3),str3,'position',[1 10]);
text(x(4),y(4),str4,'position',[1 10]);
text(x(5),y(5),str5,'position',[1 10]);
xlabel('xTicks');ylabel('MSG');
elseif isequal(bit_position,3)
subplot(3,1,3);
text(x(1:numel(x)),y(1:numel(x)),str(1:numel(x)),'position',[i/numel(x) i/numel(x)]);
% text(x(1:numel(x)),y(1:numel(x)),str(1:numel(x)),'position',[1 10]);
xlabel('xTicks');ylabel('MSG');
end
end
Adam Danz
on 11 Jun 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
on 11 Jun 2020
Edited: Life is Wonderful
on 12 Jun 2020
Remove comment!
Life is Wonderful
on 11 Jun 2020
Edited: Life is Wonderful
on 12 Jun 2020
Remove comment!
Life is Wonderful
on 11 Jun 2020
Edited: Life is Wonderful
on 12 Jun 2020
Problem statement : In 2nd figure, 1st & 2nd Text data is overlapping
: In 3nd figure, 1st , 2nd and 3rd Text data is overlapping
Requirement: From the below table , plot the text data in a Non-overlapp.
1×4 table
WeirdDuration log_autoserv1_autoserv Sublog_autoserv1_autoserv Message_autoserv1_autoserv
_____________ ______________________ _________________________ ______________________________________________________________________________________________________
00:00:00.000 {'INFO |'} {'pidfile:0016|'} {'Logged pid 4404 to /tmp/test_that_results_hatch_QIZGx2/results-07-firmware_Mosys/.autoserv_execute'}



Adam Danz
on 11 Jun 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
on 12 Jun 2020
Edited: Life is Wonderful
on 12 Jun 2020
I don't have a mental image of what text you want to plot and where the text should go in the figure.
- I want to plot text data against time of occurance/Time vs message. I have text data point on same time.
I dont' understand why you're plotting text at certain locations in the plot.
- I am not plotting text to a location. The text('position',[]) - is not used. This is an issue for now.
I don't understand what parts of the text should be included on the plot.
- I want to plot , Time vs Message.
I don't understand what determines the (x,y) coordinates of the text.
- x-axsis = time[WeirdDuration]/row,
- y-axis = message[log_autoserv1_autoserv,Sublog_autoserv1_autoserv,Message_autoserv1_autoserv]/column
WeirdDuration log_autoserv1_autoserv Sublog_autoserv1_autoserv Message_autoserv1_autoserv
_____________ ______________________ _________________________ ______________________________________________________________________________________________________
00:00:00.000 {'INFO |'} {'pidfile:0016|'} {'Logged pid 4404 to /tmp/test_that_results_hatch_QIZGx2/results-07-firmware_Mosys/.autoserv_execute'}
plot(x,y,str) ==> plot(x,y,str,'position',[ ]) , Note 'position',[ ] is missing
hTxt1 = text(app.axis,WeirdDuration,log_autoserv1_autoserv) ==> text(00:00:00.000,{'INFO |'})
hTxt2 = text(app.axis,WeirdDuration,Sublog_autoserv1_autoserv) ==> text(00:00:00.000,{'pidfile:0016|'})
hTxt3 = text(app.axis,WeirdDuration, Message_autoserv1_autoserv) ==> text(00:00:00.000,{'Logged pid 4404 to /tmp/test_that_results_hatch_QIZGx2/results-07-firmware_Mosys/.autoserv_execute'})
OK, I will take time to understand text() function and file exchange,
Thank you!
Life is Wonderful
on 12 Jun 2020
Edited: Life is Wonderful
on 12 Jun 2020
The problem statement and concept was in place.
Instead of subplots- I was adding the one figure.The attached code[appdesigner("SysDebug_AppDesign")] is where Text overlap is there. So I need your help
Adam Danz
on 12 Jun 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
on 12 Jun 2020
Edited: Life is Wonderful
on 12 Jun 2020
Hi Adam,
I understood the issue more from your figure. Thank you very much!
Let's say
- x-+.25 means we are shifting the text location by 0.25 units on time scale(x -co ordinate).
- y-+.25 means we are shifting the text location by 0.25 units on Index scale(y -co ordinate)
That means co ordinates will changes.
In case , if we use marker to indicate location and shift the text, then the problem straring " how long one can define text position shift space" ? There can be possibility of additional Text in waiting to surface on the figure
In -fact , I was asking on the same axis (x,y) points I had the multiple text data.
I don't know - how to define the concept....
K>> text(app.UIAxes,h,range,s_DropDown1(range),range,'VerticalAlignment','bottom',"FontSize",12, "Color",rand(1,3));
K>> text(app.UIAxes,h+0.25,range,s_DropDown1(range),range,'VerticalAlignment','bottom',"FontSize",12, "Color",rand(1,3))
K>> text(app.UIAxes,h,range+0.25,s_DropDown1(range),range,'VerticalAlignment','bottom',"FontSize",12, "Color",rand(1,3))
K>> text(app.UIAxes,h,range-0.25,s_DropDown1(range),range,'VerticalAlignment','bottom',"FontSize",12, "Color",rand(1,3))
K>> text(app.UIAxes,h-0.25,range,s_DropDown1(range),range,'VerticalAlignment','bottom',"FontSize",12, "Color",rand(1,3))

Adam Danz
on 12 Jun 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
on 12 Jun 2020
Yes!
Life is Wonderful
on 12 Jun 2020
Perfect - Thank you very much! Problem is solved 

Adam Danz
on 12 Jun 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
on 12 Jun 2020
Some how- I don't see accept answer option!
Accepted Answer
Adam Danz
on 12 Jun 2020
Here are two ways to control the position of text in a plot
Use Matlab's text() function
The HorizontalAlignment and VerticalAlignment properties control the text position relative to the coordinate.
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', 'Center', 'VerticalAlignment', 'Bottom')
xlim([0,4])
ylim([0,4])
The same example above can be done with this line below. The 'N' input specifies that the text should be North of the coordinates.
labelpoints(x,y,textSamples,'N','color','b') % N is for North
2 Comments
Life is Wonderful
on 19 Jul 2020
Hi Adam,
Can you please help with below link issue
You suggestion and guidance would be a great help for me ! Thank you!
Life is Wonderful
on 28 Aug 2020
Hi Adam,
Can you please help in resolving the issue ?
Thank you!
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)