my problem is I want to have a box for additional bigger comments to the graph.
How can I create this box, so that it will be always on the right bottom side outside of my graph, and it will be automatically adjusting its size to the amount of text inside? Also, if I will have longer text, I need it to be split into more lines, not just one line extremely long.
I use it like that, however I have a poor control over what is happening, this just creates a certain size in a certain place, text is cut.. please help :)
x = rand(110)*100;
y = x;
plot(x,y)
MyBox = uicontrol('style','text')
set(MyBox,'String','optional longer information to be put into diagram')
set(MyBox,'Position',[10,0,40,10])
I am afraid you can not do that automatically - Text boxes do not use callbacks. From the documentation:
Users cannot change static text interactively. Static text controls do not activate callback routines when clicked.
What you can do is call textwrap function, which will automatically wrap the text you pass to it and return new Text box position:
MyBox = uicontrol('style','text');
% set initial position - first three values are kept constant after wrap, the hight can be changed
set(MyBox,'Position',[10,10,30,10])
% adjust the height of your Text box and wrap the text
[outstring,newpos] = textwrap(MyBox,{'optional longer information to be put into diagram'});
% set new position and text
set(MyBox,'Position',newpos, 'String', outstring)
You will have to call textwrap and set(...) yourself whenever you change the string in the text box.
Related
I'm working on a mind map editor in which the user can draw boxes and write text in them. However, the TMPro input fields I'm using in those boxes have extra-wide caret when I type in them, and changing the fonts didn't solve the problem. Here are some images of the issue:
The caret is so wide that it can push the text inside out of the box:
I tried to lower the caret width in my script, but it's an int and has already been set to 1. Can you give me some possible reasons as to why this is happening?
I solved that problem by multiplying width+height of my inputfield by 100 and dividing its scale by 100.
Don't forget to increase the font size significantly.
I have a picture, for which I have the x and y coordinates for multiple objects. Each object has a name. I wish to use insertText to place the name in the middle of the object. Considering the large amount of objects per image, sometimes the text overlaps.
Currently, i use this which writes the text exactly to the middle.
I = imread(some_image.jpg); % load image
for i = 1:length(object) % for each object
m = mean(object(i,1:2))); % get the middle
I = insertText(I,m,[name]); % and write label.
end
What I want is a new label to be moved slightly, so that the newest label does not overlap with an old label.
Does any one here have an idea about how to change the position of output in the GUI matlab to be to the right side of the box and not in the center ?
i think I have to change some properties of the result text box
Check this post out: Positioning of figures
The figure Position property controls the size and location of the figure window on the screen. Monitor screen size is a property of the root Handle Graphics object. At startup, the MATLAB software determines the size of your computer screen and defines a default value for Position. This default creates figures about one-quarter of the screen's minimum extent and places them centered left to right, in the top half of the screen.
The Position Vector
MATLAB defines the figure Position property as a vector. So you may use a figure and text into it, e.g.
figure(gcf)
text(offsetX1, offsetX1, ['result 1: ' num2str(result1)])
text(offsetX2, offsetX2, ['result 2: ' num2str(result2)])
Displaying analytical results in a MATLAB GUI
This post talks about adding a static textbox with your results and positioning it.
Move GUI figure to specified location on screen:
Syntax:
movegui(h,'position')
movegui(position)
movegui(h)
movegui
The answer is pretty much trying to cover up the vauge nature of the question
I have a text item on one of my plots, placed at a certain location, with a certain orientation:
th=text(x,y,'some text','HorizontalAlignment','right','rotation',rot);
Based on its position (get(th, 'Position')), or any other property, is there any way to compute the lower bound of its bounding box? I want to place another text just below it.
You could use the Extent property. You will probably need to tweak the alignments depending on what you're after, but something like this:
th = text(x,y,'some text','HorizontalAlignment','right','rotation',rot);
ex = get(th,'Extent');
text(ex(1),ex(2),'Text Below')
I plotted few points using scatter and then label them using text. The position of these labels are same as the position of the points + some offset. Some of these text label overlap with each other and hence I moved them interactively (using mouse). I can check the new position of each of these text individually using property editor. However this is very time-consuming. Is there a better way to get the coordinates of all these text-label?
You can use findobj to get handles to text objects that are children of the current axes (or another handle... your choice):
text_handles = findobj('parent',gca,'type','text');
Then you can get the positions of these text objects:
positions = get(text_handles,'position');
You may need to do a bit more work to associate each text object with its data point - I suggest taking advantage of the property system, perhaps via the UserData field, for this, though there are many options.
If you want to do it easily later do this in your plots, for example:
h=text(2.9,7.5,'MyText');
This will put "MyText" at position 2.9, and 7.5.
Then to change the position use:
set(h,'Position',[2.5 7]);
This will change the position to 2.5 and 7.
Later if you need to see tthe position of text again use:
get(h);
Hope this helps.