

Will give you a sine wave with the color associated to the y value: Hs=surf(xx,yy,zz,yy,'EdgeColor','interp') %// color binded to "y" values View(2) %// view(0,90) %// set view in X-Y planeĪs an example of a more general case: x=linspace(0,2*pi) Shading flat %// so each line segment has a plain color Hs=surf(xx,yy,zz,cc,'EdgeColor','interp','FaceColor','none','Marker','o') Ĭolormap(custom_colormap) %// assign the colormap Zz=zeros(size(xx)) %// everything in the Z=0 plane Xx= %// create a 2D matrix based on "X" column %% // your dataĬ = M(:,3) %// extract color index for the custom colormap Matlab surf does not handle 1D data, it needs a matrix as input so we are going to give it by just duplicating each coordinate set (for example xx=).ĭon't worry though, the surface will stay as thin as a line, so the end result is not ugly. Surfaces benefit from their CData properties and a lot of useful features to exploit color maps and texture. The trick is to use a surface instead of a line object. However, is will never be as simple as you expected (unless you write a wrapper for one of the solution here you can forget about plot(x,y,)). Matplotlib uses a dictionary from its colors.py module.įor name, hex in ():įor name, hex in can also do it with a trick which works with Matlab version anterior to 2014b (as far back as 2009a at least).
#MATLAB PLOT COLORS ASSIGN COLOR NAME CODE#
This is more similar to specifying and RGB tuple rather than a named color (apart from the fact that the hex code is passed as a string), and I will not include an image of the 16 million colors you can choose from.įor more details, please refer to the matplotlib colors documentation and the source file specifying the available colors, _color_data.py.

You can also plot colors by their HTML hex code: plt.plot(, lw=4, c='#8f9805') The default Tableau colors are available in matplotlib via the 'tab:' prefix: plt.plot(, lw=4, c='tab:green') Now you have access to a plethora of named colors! If you would like to use additional named colors when plotting with matplotlib, you can use the xkcd crowdsourced color names, via the 'xkcd:' prefix: plt.plot(, lw=4, c='xkcd:baby poop green') I merged my previous updates into this section. X, Y = fig.get_dpi() * fig.get_size_inches()Īx.text(xi_text, y, name, fontsize=(h * 0.8), # Sort colors by hue, saturation, value and name.īy_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color))), name) import matplotlib.pyplot as pltĬolors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS) I really didn't change much from the matplotlib example, but here is the code for completeness. I updated the image and code to reflect that 'rebeccapurple' has been added and the three sage colors have been moved under the 'xkcd:' prefix since I posted this answer originally. The order is not identical to how I would sort by eye, but I think it gives a good overview. I prefer the colors to be grouped with similar colors, so I slightly tweaked the matplotlib answer that was mentioned in a comment above to get a color list sorted in columns. The previous answers are great, but I find it a bit difficult to get an overview of the available colors from the posted image. I constantly forget the names of the colors I want to use and keep coming back to this question =)
