4daJKong
4daJKong

Reputation: 2065

Why is the title on the middle of figure? How can I make it on the top?

The figure shows the title on the middle of the figure, like that:

enter image description here

x=[2, 3, 4, 5, 6]

y1=[186.1514196056709, 159.12401454010774, 168.58499675415746, 175.84505835379582, 176.46936542235537]

y2=[0.3016510699429101, 0.26247594932831353, 0.29913169309436605, 0.3053190632425873, 0.3186662404748315]

y3= [1.2213442807894994, 1.2553757513887367, 1.1182748303246677, 1.003606425268881, 0.9987302918527493]

fig,(l1,l2,l3) = plt.subplots(3, 1, sharex=True)
l1.plot(x,y1,'ro-',label='Calinski-Harabasz')
l2.plot(x,y2,'b^-',label='the Davies-Bouldin')
l3.plot(x,y3,'g+-',label='Silhouette Coefficient ')

l1.set_ylim(140, 200)
l2.set_ylim(0.8, 1.4)
l3.set_ylim(0.2, 0.4)

l1.spines['bottom'].set_visible(False)
l2.spines['top'].set_visible(False)
l2.spines['bottom'].set_visible(False)
l3.spines['top'].set_visible(False)
l1.xaxis.tick_top()
l2.xaxis.tick_bottom()
l3.xaxis.tick_bottom()


plt.title('The Scores in K-means Conditions',loc='center')
plt.xlabel('clusters number')
plt.ylabel('scores')
plt.show()

Upvotes: 1

Views: 507

Answers (1)

Doğu Ozan Kumru
Doğu Ozan Kumru

Reputation: 36

You create 3 different graphs, but you get results like this because you only give the title to the last one. If you move the plt.title('The Scores in K-means Conditions',loc='center') section to the top and make it the title for the 1st chart, it will appear at the top.

Upvotes: 1

Related Questions