I am comparing some algorithmic results using matplotlib.pyplot, however it is very difficult to understand what is going on since several lines have the same exact color. Is there a way to avoid this? I don't think that pyplot has only seven colors, has it?
Use legend() method to avoid overlapping of labels and autopct. To display the figure, use show() method.
show() and plt. draw() are unnecessary and / or blocking in one way or the other.
The usual way to set the line color in matplotlib is to specify it in the plot command. This can either be done by a string after the data, e.g. "r-" for a red line, or by explicitely stating the color argument.
%matplotlib inline turns on “inline plotting”, where plot graphics will appear in your notebook. This has important implications for interactivity: for inline plotting, commands in cells below the cell that outputs a plot will not affect the plot.
For Python 3, from the solutions above you can use:
colormap = plt.cm.nipy_spectral
colors = [colormap(i) for i in np.linspace(0, 1,number_of_plots)]
ax.set_prop_cycle('color', colors)
or:
import seaborn as sns
colors = sns.color_palette("hls", number_of_plots)
ax.set_prop_cycle('color', colors)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With