ash goharam
ash goharam

Reputation: 59

How to set single marker on above the bar of the graph

I have the following code for generating my graph. However I need some settings in the graph, I need the single red marker in graph to be above the bar not on the bar since its visibility is not good, its hiding the bar. I tried different solutions but it's not working. Thank you for your help.

width=.35
m1_t = pd.DataFrame({
'System':[13.77,40.72,114.59,141.71,174.59,217.95,237.26,261.8,297.46,332.25,366.08,351.9,404.33,436.06,465.13,494.56,497.43,526.82,545.34,563.61,581.92,594.94,610.23,665.7,688.82],
'Cloud':[699.52,673.49,601.76,577.89,546.8,502.07,484.37,460.50,424.14,387.32,351.01,316.27,312.93,279.82,247.59,214.86,169.4,182.47,163.05,143.42,123.92,111.27,96.27,39.95,16.98],
'Communication':[942.4,18072,18072,5019.2,9000,9000,2510.4,5019.2,5019.2,5019.2,5019.2,1256,2510.4,2510.4,2510.4,2510.4,618.8,628.8,628.8,628.8,628.8,144,144,272,272],
'data': [0.589,12.545,12.545,3.137,6.273,6.273,1.569,3.137,3.137,3.137,3.137,0.785,1.569,1.569,1.569,1.569,0.393,0.393,0.393,0.393,0.393,0.09,0.09,0.17,0.17]})
colors = ['#5DADE2', 'orange', '#D5DBDB', '#273746', '#FFDEAD']
m1_t[['System','Cloud','Communication']].plot(kind='bar', width = width,stacked=True,color=colors,figsize=(6.5, 3))
plt.ylabel("Latency (ms)")
plt.ylim(0, 20000)
m1_t['data'].plot(secondary_y=True, color='darkslategrey', marker='o', MarkerSize=2)
ax = plt.gca()
ax.scatter(21, m1_t['data'][16], label='`enter code here`latency', marker='*', c='r', zorder=1)
ax.legend(loc='center right')
plt.xlim([-width, len(m1_t['Communication']) - width])
plt.xticks(rotation=45, size=2)
ax.set_xticklabels(('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14','15', '16', '17', '18', '19','20','21','22','23','24','25'))
plt.ylim(0, 14)
plt.ylabel("data (MB)")

graph

Upvotes: 2

Views: 502

Answers (1)

werner
werner

Reputation: 14845

You could increase the y value of the highligthed point, for example by multiplying the value by 2:

ax.scatter(21, m1_t['data'][16]*2, label='latency', marker='*', c='r', zorder=1)

increase y value

Or you could hightlight the whole area around the important point by using avxspan:

ax.axvspan(20.8, 21.2, color='red', alpha=0.5)

avxspan

Upvotes: 1

Related Questions