Python 實現(xiàn)繪制子圖及子圖刻度的變換等問題
更新時間:2021年05月31日 09:47:43 作者:l8947943
這篇文章主要介紹了Python 實現(xiàn)繪制子圖及子圖刻度的變換等問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
1、涉及到圖的對比會用到子圖形式展示,先看看效果
2、繪制代碼如下
accuracy_alexnet_clef = [78.05, 78.43, 78.65, 78.61, 78.69] accuracy_resnet_clef = [84.56, 84.84, 85.07, 85.01, 85.13] accuracy_alexnet_office10 = [87.30, 87.57, 87.78, 87.72, 87.50] accuracy_resnet_office10 = [96.31, 96.35, 96.62, 96.43, 96.15] orders = ['2', '3', '5', '10', '20'] names = ['alexnet', 'resnet'] # 創(chuàng)建兩幅子圖 f, ax = plt.subplots(2,1,figsize=(6, 8)) # 第一根柱子偏移坐標 x = [i for i in range(len(orders))] # 第二根柱子偏移坐標 x1 = [i + 0.35 for i in range(len(orders))] # 兩幅子圖之間的間距 plt.subplots_adjust(wspace =0, hspace =0.4) # 選擇第一幅圖 figure_1 = ax[0] # 設(shè)置x軸偏移和標簽 figure_1.set_xticks([i+0.15 for i in x]) figure_1.set_xticklabels(orders) # 設(shè)置y軸的范圍 figure_1.set_ylim(bottom=77,top=86) # 繪制柱狀圖,x表示x軸內(nèi)容,accuracy_alexnet_clef表示y軸的內(nèi)容,alpha表示透明度,width表示柱子寬度 # label表示圖列 figure_1.bar(x, accuracy_alexnet_clef, alpha=0.7, width = 0.35, facecolor = '#4c72b0', label='Alexnet') figure_1.bar(x1, accuracy_resnet_clef, alpha=0.7, width = 0.35, facecolor = '#dd8452', label='Resnet') figure_1.set_ylabel('Accuracy%') # 設(shè)置y軸的標簽 figure_1.set_xlabel('Order') # 設(shè)置x軸的名稱 figure_1.set_title('Alexnet') # 設(shè)置圖一標題名稱 figure_1.legend() # 顯示圖一的圖例 # 選擇第二幅圖 figure_2 = ax[1] figure_1.set_xticks([i+0.15 for i in x]) figure_1.set_xticklabels(orders) figure_2.set_ylim(bottom=77,top=100) figure_2.bar(x, accuracy_alexnet_office10,alpha=0.7,width = 0.35,facecolor = '#c44e52', label='Alexnet') figure_2.bar(x1, accuracy_resnet_office10,alpha=0.7,width = 0.35,facecolor = '#5f9e6e', label='Alexnet') # figure_2.bar(orders, accuracy_resnet_clef,alpha=0.7,width = 0.35,facecolor = '#dd8452') figure_2.set_ylabel('Accuracy%') figure_2.set_xlabel('Order') figure_2.set_title('Resnet') figure_2.legend() f.suptitle('ImageCLEF_DA') # 設(shè)置總標題 plt.show()
補充:解決python中subplot繪制子圖時子圖坐標軸標簽以及標題重疊的問題
1.問題描述
在使用python的matplotlib中的subplot繪制子圖時出現(xiàn)信息相互重疊的情況。
2.解決方案
在plt.show()前面添加代碼plt.tight_layout()即可解決。
plt.subplot(211) plt.figure(1) plt.hist(x, 10) plt.title("Histogram of sample points") plt.subplot(212) plt.plot(x,X.pdf(x)) plt.title("Probability Density Function(PDF)") plt.tight_layout() plt.show()
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python寫的Discuz7.2版faq.php注入漏洞工具
這篇文章主要介紹了Python寫的Discuz7.2版faq.php注入漏洞工具,全自動的一款注入工具,針對Discuz7.2版,需要的朋友可以參考下2014-08-08基于Python實現(xiàn)簡易文檔格式轉(zhuǎn)換器
這篇文章主要介紹了基于Python和PyQT5實現(xiàn)簡易的文檔格式轉(zhuǎn)換器,支持.txt/.xlsx/.csv格式的轉(zhuǎn)換。感興趣的小伙伴可以跟隨小編一起學習一下2021-12-12完美解決TensorFlow和Keras大數(shù)據(jù)量內(nèi)存溢出的問題
這篇文章主要介紹了完美解決TensorFlow和Keras大數(shù)據(jù)量內(nèi)存溢出的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07