I usually use the second one of these:
from matplotlib.pyplot import cm
import numpy as np
#variable n below should be number of curves to plot
#version 1:
color = cm.rainbow(np.linspace(0, 1, n))
for i, c in enumerate(color):
plt.plot(x, y, c=c)
#or version 2:
color = iter(cm.rainbow(np.linspace(0, 1, n)))
for i in range(n):
c = next(color)
plt.plot(x, y, c=c)
Example of 2:

matplotlib 1.5+
You can use axes.set_prop_cycle (example).
matplotlib 1.0-1.4
You can use axes.set_color_cycle (example).
matplotlib 0.x
You can use Axes.set_default_color_cycle.
imshow can work in two ways:
- usually, it gets a 2D input, which are interpreted as scalar values which get color mapped
- on the other hand, a 3D input is interpreted as a 2D grid of explicit rgb values
So, the idea is to create such a 3D list for your values. [rgb_values] serves that goal.
imshow([rgb_values]) creates a plot going from -0.5 to 18.5 on the x-axis. That way x-positions 0, 1, ..., 18 are the centers of the cells. ax.set_xticks() can then label these positions. As it is hard to fit 19 values horizontally, the labels can be rotated a bit. (I am not sure how you want to fit both the numeric and the hex labels with the limited space. Maybe place one at the top? Or create a vertical bar?)
import matplotlib.pyplot as plt
from matplotlib.colors import hex2color
num_values = [-10000000, -5000000, -2500000, -1000000, -500000, -250000, -100000, -50000, -10000, 0, 10000, 50000, 100000, 250000, 500000, 1000000, 2500000, 5000000, 10000000]
hex_values = ['#345f79', '#367aa3', '#368cbf', '#3690c0', '#74a9cf', '#a6bddb', '#d0d1e6', '#ece7f2', '#fff7fb', '#f0f0f0', '#ffffcc', '#ffeda0', '#fed976', '#feb24c', '#fda362', '#fc7154', '#d04c67', '#bd0026', '#a64c67']
rgb_values = [hex2color(hex) for hex in hex_values]
fig, ax = plt.subplots(figsize=(12, 3))
ax.imshow([rgb_values], interpolation='nearest')
ax.set_yticks([])
# ax.set_xticks(range(len(num_values)), num_values, rotation=30)
ax.set_xticks(range(len(hex_values)), hex_values, rotation=30)
plt.tight_layout()
plt.show()

Because your num_values spans an exponential range, the colors for the values in the middle aren't being mapped correctly. It's not clear to me what your end goal is for this colormap, but if all you want to do is plot the colors and have the x-ticks show the corresponding number, you can do the following:
fig, ax = plt.subplots(figsize=(10,2))
ax.imshow((range(len(num_values)),), cmap=ListedColormap(hex_values))
ax.set_xticks(range(len(num_values)), num_values, rotation=90)
fig.tight_layout()
fig.show()

In matplotlib versions >= 1.5, you can print the rcParam called axes.prop_cycle:
print(plt.rcParams['axes.prop_cycle'].by_key()['color'])
# [u'#1f77b4', u'#ff7f0e', u'#2ca02c', u'#d62728', u'#9467bd', u'#8c564b', u'#e377c2', u'#7f7f7f', u'#bcbd22', u'#17becf']
Or equivalently, in python2:
print plt.rcParams['axes.prop_cycle'].by_key()['color']
In versions < 1.5, this was called color_cycle:
print plt.rcParams['axes.color_cycle']
# [u'b', u'g', u'r', u'c', u'm', u'y', u'k']
Note that the default color cycle changed in version 2.0.0 http://matplotlib.org/users/dflt_style_changes.html#colors-in-default-property-cycle
Often, there is no need to get the default color cycle from anywhere, as it is the default one, so just using it is sufficient.
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
t = np.arange(5)
for i in range(4):
line, = ax.plot(t,i*(t+1), linestyle = '-')
ax.plot(t,i*(t+1)+.3,color = line.get_color(), linestyle = ':')
plt.show()

In case you want to use the default color cycle for something different, there are of course several options.
"tab10" colormap
First it should be mentionned that the "tab10" colormap comprises the colors from the default color cycle, you can get it via cmap = plt.get_cmap("tab10").
Equivalent to the above would hence be
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
t = np.arange(5)
cmap = plt.get_cmap("tab10")
for i in range(4):
ax.plot(t,i*(t+1), color=cmap(i), linestyle = '-')
ax.plot(t,i*(t+1)+.3,color=cmap(i), linestyle = ':')
plt.show()
Colors from color cycle
You can also use the color cycler directly, cycle = plt.rcParams['axes.prop_cycle'].by_key()['color']. This gives list with the colors from the cycle, which you can use to iterate over.
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
t = np.arange(5)
cycle = plt.rcParams['axes.prop_cycle'].by_key()['color']
for i in range(4):
ax.plot(t,i*(t+1), color=cycle[i], linestyle = '-')
ax.plot(t,i*(t+1)+.3,color=cycle[i], linestyle = ':')
plt.show()
The CN notation
Finally, the CN notation allows to get the Nth color of the color cycle, color="C{}".format(i). This however only works for the first 10 colors (N in [0,1,...9])
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
t = np.arange(5)
for i in range(4):
ax.plot(t,i*(t+1), color="C{}".format(i), linestyle = '-')
ax.plot(t,i*(t+1)+.3,color="C{}".format(i), linestyle = ':')
plt.show()
All codes presented here produce the same plot.