I have set the following colors in the axes.color_cycle of matplotlibrc file. It works fine when I plot lines and step. But when I use it to plot vertical lines with axvline it does not use the set colors as shown in figure:
It uses matplotlib's default colors. How to make axvline continue the color cycle?
Reproducible code
import numpy as np
import matplotlib.pyplot as plt
import itertools
m = 5
n = 5
x = np.zeros(shape=(m, n))
plt.figure(figsize=(5.15, 5.15))
plt.clf()
plt.subplot(111)
marker = itertools.cycle(('o', 'v', '^', '<', '>', 's', '8', 'p'))
ax = plt.gca()
for i in range(1, n):
x = np.dot(i, [1, 1.1, 1.2, 1.3])
y = x ** 2
color = next(ax._get_lines.color_cycle)
plt.plot(x, y, linestyle='', markeredgecolor='none', marker=marker.next(), color=color, label = str(i))
plt.plot(x, y, linestyle='-', color = color)
plt.axvline(2.)
plt.axvline(3.)
plt.axhline(4.)
plt.axhline(6.)
plt.ylabel(r'y', labelpad=6)
plt.xlabel(r'x', labelpad=6)
plt.show()
You can assign a color to your vertical lines as well:
vline_color = next(ax._get_lines.color_cycle)
plt.axvline(2., color = vline_color)
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