banner



How To Remove The Matlab Graph Background Color

Colors in MATLAB plots

L. Oberbroeckling, Jump 2018.

Contents

  • Default Colors in 2D Graphs
  • Default Colors in 3D Graphs
  • Using Basic Colors in Graphs
  • Changing Colors
  • Using RGB triplets to modify colors
  • Irresolute colors in 3D Graphs
  • m-file that created this page
  • Dorsum TO MAIN PLOTTING PAGE

This certificate gives Bones ways to color graphs in MATLAB. See

http://www.mathworks.com/assist/matlab/visualize/coloring-mesh-and-surface-plots.html

and

http://www.mathworks.com/help/matlab/ref/colormap.html

for more in-depth explanations and fancier coloring, to name just 2 sources.

Default Colors in 2D Graphs

The default colors used in MATLAB changed in R2014b version. Here are the colors, in order, and their MATLAB RGB triplet.

Current color Former color
[0, 0.4470, 0.7410] [0, 0, 1]
[0.8500, 0.3250, 0.0980] [0, 0.v, 0]
[0.9290, 0.6940, 0.1250] [1, 0, 0]
[0.4940, 0.1840, 0.5560] [0, 0.75, 0.75]
[0.4660, 0.6740, 0.1880] [0.75, 0, 0.75]
[0.3010, 0.7450, 0.9330] [0.75, 0.75, 0]
[0.6350, 0.0780, 0.1840] [0.25, 0.25, 0.25]

x=linspace(-one,one); plot(x,ii*x, x,iv*x, ten,half-dozen*ten, x,8*x, 10,x*x, x,12*x, x,14*x,          'LineWidth', 2) legend('color 1',          'color 2',          'colour 3',          'color iv',          'color 5',          'colour half dozen',          'color 7',          'Location',          'SouthEast') championship('Default colors')        

Some other matter that changed starting in the R2014b version is that the agree on and hold off automatically cycles through the colors. In the past, each new plot command would starting time with the first colour (blue) and you would have to manually change the color. Now information technology will automatically move to the next color(south). See below for how to manually adjust the colors.

plot(ten,2*x,          'LineWidth', 2) hold          on          plot(10,4*x,          'LineWidth', 2) plot(10,6*x,          'LineWidth', 2) plot(x,8*x,          'LineWidth', 2) plot(x,10*x,          'LineWidth', 2) plot(x,12*x,          'LineWidth', 2) plot(x,fourteen*x,          'LineWidth', 2) concord          off          legend('color one',          'color ii',          'colour 3',          'colour 4',          'color 5',          'color half-dozen',          'color vii',          'Location',          'SouthEast') title('Hold On Now Cycles Through Colors')        

Default Colors in 3D Graphs

If using mesh(x,y,z), to change the look of it you would want to change 'EdgeColor'. Note that the name of this colormap is "parula" while previous to R2014b, it was "jet"

[ten,y]=meshgrid(linspace(0,ten)); z=sin(x).*cos(y); mesh(x,y,z) title('Default colors for mesh')        

[x,y]=meshgrid(linspace(0,ten)); z=sin(x).*cos(y); mesh(x,y,z) colormap(jet) title('Default colors for mesh BEFORE 2014b')        

Using Basic Colors in Graphs

The 8 basic colors are known by either their brusk name or long name (RGB triplets are as well included).

Long Proper name Curt Name RGB Triplet
blue b [0,0,one]
black thousand [0,0,0]
carmine r [one,0,0]
light-green thou [0,1,0]
yellow y [ane,1,0]
cyan c [0,one,1]
magenta m [i,0,one]
white due west [one,1,1]

Example of how to modify the color using short names is below. You can easily do the aforementioned thing using the long names.

10=linspace(-ane,ane); plot(x,two*x,'b') hold          on          plot(x,4*x,'k') plot(10,half-dozen*10,'r') plot(x,8*x,'1000') plot(ten,10*ten,'y') plot(x,12*x,'c') plot(10,14*x,'m') concur          off          legend('b = blueish (default)',          'chiliad = black',          'r = cherry',          'g = green',          'y = yellow',          'c = cyan',          'grand = magenta',          'Location',          'SouthEast') championship('8 Basic colors (w = white non drawn)')        

Irresolute Colors

Many times you want to have more control of what colors are used. For example, I may want some data points drawn in the same color as the bend. Or I accept a slice-wise graph that I want to have nevertheless color. There are several ways to do this. One is to apply the default colors and "resetting" the order, which is shown here. Others involve using the RGB triplet (meet next section).

ten=linspace(-10,10); y=iii*sin(x); xp=[0:pi/2:10]; yp=3*sin(xp); x1 = linspace(-x,-0.ane); x2=linspace(0.1,10); y1=1./x1; y2=1./x2; plot(x,y) hold          on          ax = gca; ax.ColorOrderIndex = 1; plot(xp,yp,'*') plot(x1,y1) ax.ColorOrderIndex = 2; plot(x2,y2) hold          off          axis          equal        

Every bit you may see, this could get confusing to keep rails of. Thus it may exist easier to employ the RGB triplets, and even name them ahead of time. This is discussed in the section below.

Using RGB triplets to change colors

Ane tin can specify colors using a vector that gives the RGB triple where in MATLAB, each of the three values are numbers from 0 to 1. Usually RGB colors have values from 0 to 255. You lot can use those numbers and separate the vector by 255 to employ within MATLAB. Thus knowing the MATLAB RGB triples for the colors can be useful. From the table higher up, we can define the default colors to piece of work with them or can put in the RGB triplet (equally a vector) directly into the plot command. Both are shown in this example.

color1=[0,0.4470, 0.7410]; t=linspace(0,10); t2=0:pi/2:10; plot(t,sin(t),          'LineWidth',2) hold          on          plot(t2,sin(t2),'s','MarkerEdge',color1,'MarkerFace',[0.9290,0.6940, 0.1250],'MarkerSize',9) concur          off          ylim([-1.5,1.5]) championship('Using MATLAB RGB triplets in 2nd graphs')        

For other colors, you tin can look upwards their RGB lawmaking on many websites such as RGB Color Codes Chart or HTML Colour Picker to meet the RGB codes (or hex codes, etc.) For example, at these RGB Color websites, you will be given R=255, G=0, B=0 for red. So you tin can use 1/255[255,0,0] to become the colour of cerise to use every bit a colour in MATLAB.

The official colour for Loyola Green is given as RGB:0-104-87, and Loyola Gray is given as RGB:200-200-200 (found on Loyola's Logos/Academy Signature page. Here'due south how i can apply those colors in MATLAB.

loyolagreen = 1/255*[0,104,87]; loyolagray = 1/255*[200,200,200];        

Now one tin can use these colors to specify the colour of markers, lines, edges, faces, etc.

t=linspace(0,x); t2=0:pi/2:10; plot(t,sin(t),'Color', loyolagreen,          'LineWidth',2) concur          on          plot(t2,sin(t2),'s','MarkerEdge','yard','MarkerFace',loyolagray,'MarkerSize',9) hold          off          ylim([-one.5,ane.v]) title('Using Other RGB colors in 2d graphs')        

Irresolute colors in 3D Graphs

If using mesh(ten,y,z), to change the look of it you can change to a different colormap as discussed in https://www.mathworks.com/assist/matlab/ref/colormap.html. This was done to a higher place when showing the previous default colormap. Here are some more.

Alarm! Once y'all modify the colormap, information technology will go along that colormap for all subsequent 3D plots within the same effigy or MATLAB session until you use close, or open a new figure window.

[x,y]=meshgrid(linspace(0,10)); z=5*sin(x).*cos(y); ax1=subplot(2,2,1);     mesh(x,y,z)     colormap(ax1,parula)     title('Default colormap(parula)') ax2=subplot(two,ii,2);     mesh(x,y,z)     colormap(ax2,jet)     title('Colormap(jet)') ax3=subplot(2,ii,3);     colormap(ax3,bone)     mesh(x,y,z)     title('Colormap(bone)') ax4=subplot(2,2,4);     colormap(ax4,summertime)     mesh(x,y,z)     title('Colormap(summer)')        

For mesh and surf, you can alter 'EdgeColor' and/or 'FaceColor' to exist uniform, rather than using colormaps.

close          all           mesh(x,y,z,'EdgeColor',color1) title('Changing EdgeColor')        

Note that you can get as fancy as you want with your own coloring schemes.  These are discussed in MATLAB's documentation (and elsewhere!) but I am non discussing hither.
surf(x,y,z) championship('Default colors for surf')        

surf(10,y,z,'EdgeColor',          'y',          'FaceColor','r') title('Changing EdgeColor and FaceColor using surf')        

surf(x,y,z,'EdgeColor',loyolagreen,'FaceColor',loyolagray) title('Using RGB colors in 3D graphs')        

g-file that created this page

Back TO Chief PLOTTING Page

How To Remove The Matlab Graph Background Color,

Source: http://math.loyola.edu/~loberbro/matlab/html/colorsInMatlab.html

Posted by: christoffersothemnioncy64.blogspot.com

0 Response to "How To Remove The Matlab Graph Background Color"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel