Multicolored Line With Strings Linecolllection
I'm using linecollection from matplotlib in order to create multi colored line similar to this example: http://matplotlib.org/examples/pylab_examples/multicolored_line.html but ins
Solution 1:
Okay I managed to do this, the code below if you need. The data(gbpndupl) im plotting is simple Series where index column is publisher names and the other column are the numbers. I also uploaded the image of how it looks like.
from matplotlib.collections import LineCollection
plt.figure(figsize=(15, 5))
x=np.arange(40)
y=gbpndupl.iloc[:40]
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lc = LineCollection(segments, cmap='plasma',norm=plt.Normalize(0, 10))
#norm can be changed to decide how fast color changes
lc.set_linewidth(3)
lc.set_array(x)
plt.xlim(min(x), max(x))
plt.ylim(min(y), max(y))
plt.gca().add_collection(lc)
labels=list(gbpndupl.iloc[:40].index)
plt.xticks(x, labels, rotation='vertical');
Post a Comment for "Multicolored Line With Strings Linecolllection"