Text overlapp in uifigure plot
30 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam Danz
2020-6-10
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
2020-6-10
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));
Adam Danz
2020-6-10
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
2020-6-11
编辑:Life is Wonderful
2020-6-11
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
2020-6-11
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
2020-6-11
编辑:Life is Wonderful
2020-6-12
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
2020-6-11
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
2020-6-12
编辑:Life is Wonderful
2020-6-12
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
2020-6-12
编辑:Life is Wonderful
2020-6-12
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
2020-6-12
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
2020-6-12
编辑:Life is Wonderful
2020-6-12
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
2020-6-12
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')
Adam Danz
2020-6-12
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
Adam Danz
2020-6-12
That's because this discussion has been in the comments section. I just added an answer that summarizes the solution.
采纳的回答
Adam Danz
2020-6-12
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 个评论
Life is Wonderful
2020-7-19
Hi Adam,
Can you please help with below link issue
You suggestion and guidance would be a great help for me ! Thank you!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)