I have this code:
plist = ['p5', 'p14', 'p23', 'p32', 'p41', 'p50', 'p59', 'p68', 'p77', 'p85', 'p95']
for pltcount in range(len(plist)):
plt.plot(data1[pltcount], np.exp(data2)[pltcount], marker='o', label=str(plist[pltcount]))
plt.legend()
plt.show()
This is using the plt.style.use('fivethirtyeight')
to make the plots nicer. I have found examples where I manually assign the colors. What if I want it to be automatic and from some well-known palettes?
The default interactive figure background color has changed from grey to white, which matches the default background color used when saving. in your matplotlibrc file.
You can remove duplicate labels by putting them in a dictionary before calling legend . This is because dicts can't have duplicate keys.
bbox_to_anchor=[x0, y0] will create a bounding box with lower left corner at position [x0, y0] . The extend of the bounding box is zero - being equivalent to bbox_to_anchor=[x0, y0, 0, 0] . The legend will then be placed 'inside' this box and overlapp it according to the specified loc parameter.
How about the colors of the rainbow? The key here is to use ax.set_prop_cycle
to assign colors to each line.
NUM_COLORS = len(plist)
cm = plt.get_cmap('gist_rainbow')
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_prop_cycle('color', [cm(1.*i/NUM_COLORS) for i in range(NUM_COLORS)])
# Or,
# ax.set_prop_cycle(color=[cm(1.*i/NUM_COLORS) for i in range(NUM_COLORS)])
for i, p in enumerate(plist):
ax.plot(data1[i], np.exp(data2)[i], marker='o', label=str(p))
plt.legend()
plt.show()
Borrowed from here. Other options possible.
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