use matplotlib to draw a mixed graph of polyline and column but the polyline is not displayed

As @Mr. T commented, you seem to be confusing the 1st and 2nd axes. If the second axis is a bar graph, then the rest of the time it is the first axis, isn’t it?

fig = plt.figure(figsize=(12,9))

ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()

ax1.set_ylim(0, 3)
ax2.set_ylim(95, 130)


node = [110,118,121,107,123]
x = np.arange(5)
bar_wigth = 0.45

x_list= ['$node_1$','$node_2$','$node_3$','$node_4$','$node_5$'],node,bar_wigth,color='green',label='$node_iNum$',alpha=0.6, tick_label=x_list)

l=[i for i in range(5)]

ax1.plot(l, t_score,'r-', label='$t_{th}$')
ax1.plot(l, quezhi,'b--', label='$t_{score}$')
ax1.plot(l, t_score, 'ro', l, quezhi,'b^')

for a, b in zip(l, t_score):
    ax1.text(a, b, b, ha='center', va='bottom', fontsize=10)
for a, b in zip(l, quezhi):
    ax1.text(a, b, b, ha='center', va='bottom', fontsize=10)

fig.legend(bbox_to_anchor=(0, 1), bbox_transform=ax2.transAxes, loc='upper left', prop=font2)

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top