How can I add an extra text line in a legend of matlab graph? - matlab-figure

I need some help!!!!!
I have following legend in a line graph in Matlab:
--- Esme
--- Manta
--- Senchu
with their respectives lines --- , but I want to have a extra text in the top of the legend like:
SOURCES
--- Esme
--- Manta
--- Senchu
How can I add such text?
Thank you very much!!!

If you are using a MATLAB version prior to 2014b, you can use the method detailed here:
hLeg = legend('Esme','Manta','Senchu'); %// Create the legend and get a handle to it.
hTitle = get(hLeg,'Title'); %// Get a handle to the legend's Title.
set(hTitle,'String','SOURCES'); %// Set the desired title.
For newer versions of MATLAB (or handle graphics, to be precise) the above is no longer an option (as mentioned here), in which case you can use this File Exchange submission to get the desired result. This method works by obtaining the Position of the legend, creating an axes at the same coordinates and then set its Title to something.
Please also refer to this UndocumentedMatlab post which discusses your exact question.

Related

How can I add an icon in a label?

I have 2 questions need your help.
I would like to add a button on each plot to be a setting button. I use label with event listener and it works well ( as shown in attached file). However, my client asked me to change from normal text to graphic icon? How should I proceed?
As you can see from the attached image, the third plot is macd series. The value rage is from -3e-8 to 3e-8 (by my observation). I manually set the maximum and minimum, and it get incorrect scale as shown.
How should I set the maximum and minimum for yScale?
I don't know how to get maximum and minimum value from a series. Can you suggest me?
A1 – Unfortunately, the current version of AnyChart doesn't provide an opportunity to add custom-made buttons inside the chart. But you can use a trick and use stage based layout. It means that the container includes a stage. The stage includes the stock chart all other elements by layers. Using this approach you can place an image (icon) upon the plot and set a listener just as for the 'settings' label.
For details, please, check the sample in the comment below.
A2 - We are planning to fix this behavior in 8.4.2 update (approximately by the end of November 2018).
I will notify you when the fix becomes available.
As a temporary workaround, you can get min /max value from your MACD indicator. For details, please, check the sample in the comment below.
You can apply min/max to the yScale of plot #0 like this:
chart.plot(0).yScale().minimum(minValue);
chart.plot(0).yScale().maximum(maxValue);
We are glad to inform you that we have released 8.4.2 update which brings many fixes and improvements. This update also includes a fix on the issue you reported. Now calculation of min/max of Y-scale works properly with small values. Update your binaries to get the fix.

Simple file legend in Xmgrace

I am using xmgrace to plot several graphs on a shared axed, from a two-column data file like so:
# title "RMSD"
# xaxis label "Time (ns)"
# yaxis label "RMSD (nm)"
#TYPE xy
# subtitle "C-alpha after lsq fit to C-alpha"
1.7125001 0.0005074
1.7225001 0.0635904
1.7325001 0.0747008
1.7425001 0.0707590
1.7525001 0.0821623
1.7625000 0.0842335
1.7725000 0.0929994
1.7825000 0.0938834
1.7925001 0.1014052
1.8025001 0.1107717
1.8125001 0.1106072
1.8225001 0.1032858
1.8325001 0.0967231
1.8425001 0.1072746
So, I call the command to show me all graphs on the GUI
xmgrace 1.xvg rmsd_amber_2.xvg rmsd_3.xvg
Is it possible to automatically use the filenames as the labels for the legend, using an option found within the GUI of xmgrace? So far xmgrace automatically uses different line colors for each data series, but does not show the filename as the data label.
If this is not possible, please suggest me another GUI software for Linux which is able to open xvg files from the terminal for its visualization "on the fly".
Thanks !
Xmgrace does not do what you want
The xmgrace help (shown by calling xmgrace --help at the terminal) shows that there is no command line flag to specify data set legend titles. If that were the case you could probably come up with some bash commands to parse the title from your data files.
But there is another way
As an alternative, you can load a parameters file containing the correct titles. If you save any parameters file from within the xmgrace GUI and load it in a text editor, you will see that almost every aspect of Plot, Graph and Set appearance properties can be controlled.
However, it is not all needed; we can delete almost all of that information and just keep the lines related to our data set legend titles (everything else will just take the default values).
Solution
A minimal parameter file "template.par" might contain just the following four lines:
with g0
s0 legend "title0"
s1 legend "title1"
s2 legend "title2"
where in your case "title1" would be "RMSD".
You can then use xmgrace -param template.par 1.xvg rmsd_amber_2.xvg rmsd_3.xvg to create the plot.
Automating it
So far so good, but you want to create template.par automatically by parsing your chosen bunch of .xvg files. You could probably achieve this in any number of different ways using a bash script or even a bash one-liner.

How to set image in axes in matlab GUI?

i have a code which gives several images as ouput and i want to set all these images in particular axes in GUI in matlab. I'm trying to make a GUI of the code.
For eg.
figure,imshow(s1);
figure,imshow(s2);
figure,imshow(s2&s1);
and i want to set the output image of first command in, say axes3, output image of second command in axes4 and similarly last output image in axes5.
Although i know i need to use
set(handles.axes...)
command but i don't know the exact syntax on how to make the image be shown in particular axes.
Please give explain on how to make this happen with any suitable example. Thanks in advance.
One line solution (for each image) is to set the axis as the parent of the image within the imshow command;
imshow(image_Data,'Parent',handles.axes1)
There should be no need to open the additional figure windows ( assuming the axes are with the gui...)
So specifically for the question above:
imshow(s1,'Parent',handles.axes3);
imshow(s2,'Parent',handles.axes4);
imshow(s2&s1,'Parent',handles.axes5);
First you should create an axes box in your gui, then in tag section get a name i.e. (original) and finaly in editor when you want to use it code something like this
A = imread (Path);
axes(handles.original);
imshow(A);
I hope to help you...

What are the jqplot default series colors?

I'm plotting some data on a jqPlot pie chart, and would like to get at the slice colors.
I'm aware of the possibility to set the slices to colors I set myself. I want to avoid this because the default colors contrast nicely from one to the next slice. Also, the slices highlight on mouse-over, and these highlight-colors are also good looking in the whole. It seems too much work to create a whole new color-scheme and then apply it to the plot when jqPlot already has a good thing built in.
I want to get at the slice colors, because I need to give additional information on certain slices, and will do this outside the plot. Re-using the slice colors would additionally allow me to forego using a legend in the plot itself, and creating my own table with "slice color - name - additional information" which then serves both as legend and source of additional information.
Is there a source of the default colors somewhere? Or is there a way to programmatically extract them?
Ok, managed to find it by delving in the actual code, as the info in the documentation on the website of jqPlot is out of date on this.
For other people wanting to get the default colors:
jquery.jqplot.js, line 354: defaultColors: [ "#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc", "#c747a3", "#cddf54", "#FBD178", "#26B4E3", "#bd70c7"]
jquery.jqplot.js, line 355: defaultNegativeColors: [ "#498991", "#C08840", "#9F9274", "#546D61", "#646C4A", "#6F6621", "#6E3F5F", "#4F64B0", "#A89050", "#C45923", "#187399", "#945381", "#959E5C", "#C7AF7B", "#478396", "#907294"]
The highlight colors are generated automatically in the function $.jqplot.computeHighlightColors (line 3775 of jquery.jqplot.js). I haven't deduced the actual highlight colors as I don't need them for my purposes, but if anyone else is looking for them, that's where you can start from.
(Line numbers based on version 1.0.8, revision 1250.)
As far as I can tell & also according to the documentation, when the array is exhausted, the colors starts over from the beginning.
According to Gimp colorpicker, jqPlot default series colors used in this example are - clockwise from orange to blue :
#eaa228 - (#efbc67 if highlighted),
#c5b47f - (#d5c9a4 if highlighted),
#579575 - (#88b39d if highlighted),
#839557 - (#a7b388 if highlighted),
#958c12 - (#b3ad58 if highlighted),
#4bb2c5 - (#80c8d5 if highlighted).
Hope it will help you.
EDIT : Please see in this link default series colors specified by jqplot

mapped imshow does not work in subplot if different palette

I found that apparently, a mapped version of imshow function does not work in subplot. Is this by design?
The following script
rgb=imread('../FruitSample_small.png');
[ind,map]=rgb2ind(rgb,4);
figure
imshow(ind,map)
figure
subplot(5,1,1);
imshow(ind,map)
subplot(5,1,2);
imshow(ind==0)
subplot(5,1,3);
imshow(ind==1)
subplot(5,1,4);
imshow(ind==2)
subplot(5,1,5);
imshow(ind==3)
produces the following result
i.e. mapped version looks black. If I plot mapped version only (5 times) it looks ok. I.e. subsequent plotting apparently change the palette.
How to plot all these 5 images on same figure then?
Colormap is a property of the figure, not the axis. The second call to imshow resets the Colormap for the entire figure. Here is some more information and a Matlab file exchange solution to the problem. If you download the function described in that link, freezeColors, you can use it in your code like this.
rgb=imread('peppers.png'); % example image included in matlab
[ind,map]=rgb2ind(rgb,4);
figure
imshow(ind,map)
figure
subplot(5,1,1);
imshow(ind,map)
freezeColors % keep colors the same after other subplots are displayed
subplot(5,1,2);
imshow(ind==0)
freezeColors
subplot(5,1,3);
imshow(ind==1)
subplot(5,1,4);
imshow(ind==2)
subplot(5,1,5);
imshow(ind==3)
And the resulting second figure will look like this:

Resources