PixelPioneer
PixelPioneer

Reputation: 4170

Matplotlib : single line chart with different markers

I have a list for markers on my time series depicting a trade. First index in each each list of the bigger list is the index where i want my marker on the line chart. Now I want a different marker for buy and sell

[[109, 'sell'],
 [122, 'buy'],
 [122, 'sell'],
 [127, 'buy'],
 [131, 'sell'],
 [142, 'buy'],
 [142, 'sell'],
 [150, 'buy']]

code:

fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(1,1,1)
ax.set_ylim( min(timeSeriesList_1)-0.5, max(timeSeriesList_1)+0.5)
start, end = 0, len(timeSeriesList_index)
stepsize = 10
ax.xaxis.set_ticks(np.arange(start, end, stepsize))
ax.set_xticklabels(timeSeriesList_index2, rotation=50)

## change required here:
ax.plot(timeSeriesList_1, '-gD', markevery= [ x[0] for x in markers_on_list1])

This is how my chart looks:

enter image description here

Please tell me, how I can have different markers for buy and sell.

Upvotes: 0

Views: 624

Answers (1)

pathoren
pathoren

Reputation: 1666

Create two new arrays, one buy-array and one sell-array and plot them individually, with different markers. To create the two arrays you can use list-comprehension

buy = [x[0] for x in your_array if x[1]=='buy']
sell = [x[0] for x in your_array if x[1]=='sell']

Upvotes: 1

Related Questions