I happened to see a figure window on the internet as Fig. 2. How do I change the appearance of the figure window in MATLAB to darker background (Fig. 1), for example, instead of the default white one (Fig. 2)? I believe it's somewhere for user setting.
Fig. 1
Fig. 2
There are a few ways you can do this.
Right click on Figure 1, just outside of the plot, to open a context menu. Select Color and chose the darker color square that you want your background to match. (Works on MATLAB 2019.)
Get the handle to your current figure and change background property directly. You can use gcf to get the current figure's handle (the one most recently selected) and then set the background color using a vector containing the red, blue, and green values you want like so:
set(gcf, 'color', [0.8, 0.8, 0.8]);
You can initialize a figure with the desired background color like so:
f = figure('color', [0.8, 0.8, 0.8]);
A black background color would be [0, 0, 0].
Related
I have installed Matlab R2021a, and when I run the command scatterplot for a vector, I get a figure as below:
I mean black and yellow. However the default colors in older versions is as follows:
I mean the colors are white and blue.
My concern, I need my MATLAB shows the colors of the figure as shown in older version, I mean with white and blue colors.
The behavior indeed changed in R2021a as mentioned in the release notes:
Visual appearance updates to plots generated with eyediagram and scatterplot functions.
The eyediagram and scatterplot functions now provide black plot backgrounds by default.
You can change the colors as desired by you by modifying the properties of axis/figure as shown below:
%Taking the example from the documentation
d = (0:63)';
s = qammod(d,64);
scatterplot(s);
%Modifying the colors
h=gca; %Axis handle
h.Title.Color='k' %Color of title
h.Children.Color='b'; %Color of points
h.YColor='k'; %Y-axis color including ylabel
h.XColor='k'; %X-axis color including xlabel
h.Color ='w'; %inside-axis color
h.Parent.Color='w' %outside-axis color
Without modification, we get this:
After modification, as desired, we get this:
Problem
I am plotting two different data sets in two different plots, and I want the graph in the same colour (blue). Obviously, I thought this is easily done by setting the colour of the markers and the lines, but although I use the same RGB code the plots appear with a different blue.
The illustrations below show the different appearance and this problem is the same if looked at in Matlab or exported as png, pdf, or jpeg. A colour print version also shows a different color. I know the colors are similar but if looked at properly they are not the same. And just to make sure, I do export them in the same size, same properties, same everything.
Question
Do I maybe have a simply plotting mistake ? Or is there a way to fix this ? I cant find a way to solve the problem.
Help is very appreciated!
Plot1
Plot2
Plot 3
Code 1
y=[0.3700 0.3600 0.350 0.3398 0.325 0.30]
h=plot(1:6,y,'Marker','o','Color',[ 0 0.4470 0.7410], 'MarkerFaceColor', [ 0 0.4470 0.7410], 'LineWidth', 1.5)
hold on
ax=gca;
ax.YLabel=ylabel('Test');
ax.XLabel = xlabel('Year');
l=legend('Whatever the legend says')
set([gca,ax.XLabel,ax.YLabel], 'FontName', 'Helvetica','FontSize', 8)
set(l,'Fontsize',8,'Location', 'southoutside', 'Orientation','horizontal')
set(gca,'LineWidth',1.0)
hold off**
Code 2
h=figure
hold on
yyaxis left
l1=plot(1:6,1:6);
l2=plot(1:6,2:7);
hYLabel=ylabel('Test');
yyaxis right
r1=plot(1:6,3:8);
hYLabel=ylabel('Test');
hXLabel = xlabel('Test');
a=sprintf('TestTest\n Test');
b=sprintf('Test Test\n Test');
c=sprintf('Test & Test\nTest Test');
hLegend=legend([l1,l2,r1,], a, b, c);
set([gca,hXLabel,hYLabel,hLegend] , 'FontName' , 'Helvetica','FontSize', 8)
set(hLegend,'Fontsize',8,'Location', 'southoutside', 'Orientation','horizontal')
set(gca,'LineWidth',1.0)
ax=gca;
set(l1, 'LineWidth',1.5,'LineStyle','-','Color',[0 0.447 0.7410])
set(l2, 'LineWidth',1.5,'LineStyle','-.','Color',[0 0.447 0.7410])
set(r1, 'LineWidth',1.5,'LineStyle','-')
hold off
Recent versions of MATLAB use anti-aliasing when displaying and printing graphics (unless explicitly disabled), so it is possible that a thinner line of the same color may appear lighter than a thicker line of that same color.
You could optionally disable the anti-aliasing of a figure
set(gcf, 'GraphicsSmoothing', 'off')
Or globallly for all figures
set(0, 'DefaultFigureGraphicsSmoothing', 'off')
All of the images you have posted above are the same shade of blue when you use a pixel color inspection tool rather than relying on your eye.
does anyone know what's the command or way to plot with different colors besides the preset color, i.e., b,g,r,c,m,y,k? I would prefer to use my own customize colors instead of these....
Cheers
Use the Color property with a ColorSpec triple:
plot(x, y, 'Color', [0.5, 1.0, 0.0], 'LineStyle', '--')
The vector here contains RGB values between 0.0 and 1.0. The Lineseries and ColorSpec documentation entries have more information about this.
From the matlab docs:
ColorOrder: m-by-3 matrix of RGB values
Colors to use for multiline plots. Defines the colors used by the plot
and plot3 functions to color each line plotted. If you do not specify
a line color with plot and plot3, these functions cycle through the
ColorOrder property to obtain the color for each line plotted. To
obtain the current ColorOrder, which might be set during startup, get
the property value:
get(gca,'ColorOrder') Note that if the axes NextPlot property is
replace (the default), high-level functions like plot reset the
ColorOrder property before determining the colors to use. If you want
MATLAB to use a ColorOrder that is different from the default, set
NextPlot to replacechildren. You can also specify your own default
ColorOrder.
All together, this means you want the commands:
figure();
axis();
set(gca, 'colororder', <color matrix>, 'nextplot', 'replacechildren');
plot(x,y);
I had the same problem with the limited set of preset colours MATLAB made available. So, I created this page on my website, where you can choose from a large palette of non-standard colours, and the colour code is pasted directly to your clipboard:
http://www.shirt-ediss.me/matlab-octave-more-colours/
I'm trying to make a legend for a colormapped image that's been made from a label image and custom color map using label2rgb. Basically I want a legend that shows small rectangular samples of the colormap colors along with custom labels.
I would like to be able to set the color of the labels and the background. The image is displayed using imshow, and apparently legend has no effect on such figures.
I've tried a little hack around this using colorbar as shown below, but I'm pretty unsatisfied with it since if I resize the plot window everything gets thrown off.
Can anyone tell me how this type of legend should be made, preferably in a way so it floats and moves itself as necessary when the figure window is resized. If this is not possible, then can someone tell me how to either color the label text of a colorbar or give the colorbar's bounding box (encompassing its labels) a background color? As you can see, if I hadn't manually added a background white box, the labels would be invisible.
Thanks.
label_image = zeros(768, 1024);
label_image(100:400, 500:600)=1;
label_image(500:600, 100:600)=2;
label_image(25:300, 100:400)=3;
custom_colormap = [ 0 1 0; 1 0 0; 0 0 1;];
label_image = label2rgb(label_image, custom_colormap, [0 0 0]);
% Make a white backround for the colorbar.
% Don't want to have to do this line.
label_image(25:140, 775:1010,:)=255;
% Show the image
imshow(label_image, 'InitialMagnification', 50);
% Here, I would like to be able to set colorbar label text color and/ or
% colorbar bounding box background color, or better yet, use some variant
% on the legend function to do this automatically
colormap(custom_colormap);
labels={'Both', 'Always Moving', 'Moved'};
hcb=colorbar('peer',gca,...
[0.7 0.8 0.03 0.1],...
'YTickLabel',labels,...
'XAxisLocation','bottom',...
'TickLength',[0 0],...
'Color',[1 0 1]);
You want to set the color of the x and y axes of the colorbar, respectively.
set(hcb,'ycolor','w','xcolor','w')
Thus, you wont have to put the white rectangle. Check get(hcb) to see a list of all the properties you can modify.
There is a axes named image in which I show the image when the user presses the browse button.
imshow(orgImg, 'Parent', handles.image);
Then I do image processing stuff.
There is a clear button to clear that image shown in image axes after done all the processing.
I used cla(handles.image,'reset');
This clear the image from axes. But, it displays the XTick and YTick as 0, 0.5, 1, 1.5 and so on and also XColor and YColor as black.
I don't want XTick and YTick values to be displayed on axes and also color should be white. But I need to display the axes without above values. Now it shows the axes with above values.
How can I remove those properties?
After you clear the image, issue this command
set(gca,'xtick',[],'ytick',[],'Xcolor','w','Ycolor','w')
you can replace gca with your current handle.
The easiest solution may actually be to leave out the 'reset' argument to CLA:
cla(handles.image);
This will have the effect of clearing the image object from the axes, but leaving the axes settings unchanged (i.e. the axes will still be invisible).