I'm trying to plot several kernel density estimations on the same graph, and I want them to all be different colors. I have a kludged solution using a string `'rgbcmyk'`

and stepping through it for each separate plot, but I start having duplicates after 7 iterations. Is there an easier/more efficient way to do this, and with more color options?

```
for n=1:10
source(n).data=normrnd(rand()*100,abs(rand()*50),100,1); %generate random data
end
cstring='rgbcmyk'; % color string
figure
hold on
for n=1:length(source)
[f,x]=ksdensity(source(n).data); % calculate the distribution
plot(x,f,cstring(mod(n,7)+1)) % plot with a different color each time
end
```

This question is related to
`matlab`

`plot`

`matlab-figure`

You could use a colormap such as HSV to generate a set of colors. For example:

```
cc=hsv(12);
figure;
hold on;
for i=1:12
plot([0 1],[0 i],'color',cc(i,:));
end
```

MATLAB has 13 different named colormaps (*'doc colormap'* lists them all).

Another option for plotting lines in different colors is to use the *LineStyleOrder* property; see Defining the Color of Lines for Plotting in the MATLAB documentation for more information.

- how to open .mat file without using MATLAB?
- SQL server stored procedure return a table
- Python equivalent to 'hold on' in Matlab
- Octave/Matlab: Adding new elements to a vector
- How can I make a "color map" plot in matlab?
- How to display (print) vector in Matlab?
- Correlation between two vectors?
- How to plot a 2D FFT in Matlab?
- How can I find the maximum value and its index in array in MATLAB?
- How to save a figure in MATLAB from the command line?
- Differences between Octave and MATLAB?
- Loop through files in a folder in matlab
- size of NumPy array
- What does operator "dot" (.) mean?
- Understanding Matlab FFT example
- A tool to convert MATLAB code to Python
- Changing Fonts Size in Matlab Plots
- How to normalize a signal to zero mean and unit variance?
- How to concat string + i?
- How to search for a string in cell array in MATLAB?
- How to get the number of columns in a matrix?
- Create an array of strings
- Optional args in MATLAB functions
- Matlab: Running an m-file from command-line
- MATLAB, Filling in the area between two sets of data, lines in one figure
- What is the Python equivalent of Matlab's tic and toc functions?
- How to normalize a histogram in MATLAB?
- How to represent e^(-t^2) in MATLAB?
- Setting graph figure size
- How to save a plot into a PDF file without a large margin around
- How to display with n decimal places in Matlab
- Generate a random number in a certain range in MATLAB
- How do I initialise all entries of a matrix with a specific value?
- how to stop a running script in Matlab
- Import CSV file with mixed data types
- How to change the window title of a MATLAB plotting figure?
- MATLAB - multiple return values from a function?
- How to a convert a date to a number and back again in MATLAB
- Is it possible to define more than one function per file in MATLAB, and access them from outside that file?
- How to iterate over a column vector in Matlab?
- How to install toolbox for MATLAB
- How can I count the number of elements of a given value in a matrix?
- Reading a text file in MATLAB line by line
- How do I import/include MATLAB functions?
- Iterating through struct fieldnames in MATLAB
- Create a 3D matrix
- Gaussian filter in MATLAB
- the easiest way to convert matrix to one row vector
- How to get all files under a specific directory in MATLAB?
- How to delete zero components in a vector in Matlab?
- [Move to Automatically plot different colored lines]

- Fine control over the font size in Seaborn plots for academic papers
- Why do many examples use `fig, ax = plt.subplots()` in Matplotlib/pyplot/python
- Modify the legend of pandas bar plot
- Format y axis as percent
- Simple line plots using seaborn
- Plot bar graph from Pandas DataFrame
- Plotting multiple lines, in different colors, with pandas dataframe
- Plotting in a non-blocking way with Matplotlib
- What does the error "arguments imply differing number of rows: x, y" mean?
- matplotlib get ylim values
- How to plot a function curve in R
- How to add title to subplots in Matplotlib?
- How to plot ROC curve in Python
- Change grid interval and specify tick labels in Matplotlib
- Reduce size of legend area in barplot
- Error in plot.new() : figure margins too large, Scatter plot
- Python how to plot graph sine wave
- Plot mean and standard deviation
- Code for best fit straight line of a scatter plot in python
- Plotting a list of (x, y) coordinates in python matplotlib
- Error in plot.window(...) : need finite 'xlim' values
- multiple plot in one figure in Python
- How to combine 2 plots (ggplot) into one plot?
- Adjust plot title (main) position
- Stacked Bar Plot in R
- how to draw directed graphs using networkx in python?
- Overlay normal curve to histogram in R
- Plot a line graph, error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
- Plot Normal distribution with Matplotlib
- Plotting multiple time series on the same plot using ggplot()
- Add missing dates to pandas dataframe
- Adding a legend to PyPlot in Matplotlib in the simplest manner possible
- How to plot time series in python
- How to plot two columns of a pandas data frame using points?
- Create own colormap using matplotlib and plot color scale
- Colorplot of 2D array matplotlib
- R barplot Y-axis scale too short
- Plot a bar using matplotlib using a dictionary
- 3D Plotting from X, Y, Z Data, Excel or other Tools
- How to set xlim and ylim for a subplot in matplotlib
- How to export plots from matplotlib with transparent background?
- How can I make a "color map" plot in matlab?
- Set the intervals of x-axis using r
- Label points in geom_point
- Add error bars to show standard deviation on a plot in R
- Plotting of 1-dimensional Gaussian distribution function
- Plot multiple lines (data series) each with unique color in R
- How to change legend title in ggplot
- Plot multiple boxplot in one graph
- Increase distance between text and title on the y-axis
- [Move to Automatically plot different colored lines]