最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python matplotlib生成圖片背景透明的示例代碼

 更新時間:2019年08月30日 09:30:18   作者:hfut_jf  
這篇文章主要介紹了Python matplotlib生成圖片背景透明的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

使用matplotlib生成圖片,想要背景透明,而且圖例部分也顯示透明效果,找到了大概的設(shè)置方法,特此記錄。

# coding=utf-8
# matplotlib背景透明示例圖
# python 3.5
 
import numpy as np
import matplotlib.pyplot as plt
from pylab import mpl
import scipy.stats as stats
 
# 設(shè)置中文字體
mpl.rcParams['font.sans-serif'] = ['SimHei']
 
 
def autolabel(rects):
  # attach some text labels
  for rect in rects:
    height = rect.get_height()
    # 設(shè)置標(biāo)注文字及位置
    ax.text(rect.get_x() + rect.get_width() / 2, 0.03 + height, '%.4f' % height, ha='center', va='bottom')
 
# 數(shù)據(jù)
testData = [[0.87, 0.40, 0.56],
      [0.97, 0.50, 0.33],
      [0.88, 0.30, 0.44],
      [0.25, 0.23, 0.17],
      [0.73, 0.33, 0.45]]
 
N = 3
width = 0.5
ind = np.arange(width, width*6*N, width*6)
 
fig, ax = plt.subplots()
rectsTest1 = ax.bar(ind, (testData[0][0], testData[0][1], testData[0][2]), width, color=(0, 0, 1, 1), edgecolor=(0, 0, 1, 1))
 
rectsTest2 = ax.bar(ind + width, (testData[1][0], testData[1][1], testData[1][2]), width, color=(1, 0, 0, 1), edgecolor=(1, 0, 0, 1))
 
rectsTest3 = ax.bar(ind + 2*width, (testData[2][0], testData[2][1], testData[2][2]), width, color=(0, 1, 0, 1), edgecolor=(0, 1, 0, 1))
 
rectsTest4 = ax.bar(ind + 3*width, (testData[3][0], testData[3][1], testData[3][2]), width, color=(1, 0.6471, 0, 1), edgecolor=(1, 0.6471, 0, 1))
 
rectsTest5 = ax.bar(ind + 4*width, (testData[4][0], testData[4][1], testData[4][2]), width, color=(0.5804, 0, 0.8275, 1), edgecolor=(0.5804, 0, 0.8275, 1))
 
ax.set_xlim(0, 9.5)
ax.set_ylim(0, 1.4)
ax.set_ylabel('數(shù)值')
ax.yaxis.grid(True)
ax.set_xticks(ind + width * 2.5)
ax.set_xticklabels(('P', 'R', 'F'))
 
# 設(shè)置圖例
legend = ax.legend((rectsTest1, rectsTest2, rectsTest3, rectsTest4, rectsTest5), ('test1', 'test2', 'test3', 'test4', 'test5'))
frame = legend.get_frame()
frame.set_alpha(1)
frame.set_facecolor('none') # 設(shè)置圖例legend背景透明
 
# 給每個數(shù)據(jù)矩形標(biāo)注數(shù)值
autolabel(rectsTest1)
autolabel(rectsTest2)
autolabel(rectsTest3)
autolabel(rectsTest4)
autolabel(rectsTest5)
 
plt.savefig('C:/Users/XX/Desktop/test.png', format='png', bbox_inches='tight', transparent=True, dpi=600) # bbox_inches='tight' 圖片邊界空白緊致, 背景透明
效

效果可能在網(wǎng)頁上看不出來,但還是把圖片貼上來吧。


以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python使用openpyxl庫讀取Excel文件數(shù)據(jù)

    python使用openpyxl庫讀取Excel文件數(shù)據(jù)

    openpyxl是一個功能強大的庫,可以輕松地實現(xiàn)Excel文件的讀寫操作,本文將介紹如何使用openpyxl庫讀取Excel文件中的數(shù)據(jù),感興趣的小伙伴可以了解下
    2023-11-11
  • Numpy維度知識總結(jié)

    Numpy維度知識總結(jié)

    這篇文章主要介紹了Numpy維度知識總結(jié),因為在numpy里一維既可以做行向量也可以做列向量,那對于任意一個給定的一維向量,我們就無法確定他到底是行向量還是列向量,為了防止這種尷尬的境地,習(xí)慣上用二維矩陣而不是一維矩陣來表示行向量和列向量,需要的朋友可以參考下
    2023-09-09
  • 讓python json encode datetime類型

    讓python json encode datetime類型

    python2.6+ 自帶的json模塊,不支持datetime的json encode,每次都需要手動轉(zhuǎn)為字符串,很累人,我們可以自己封裝一個簡單的方法處理此問題。
    2010-12-12
  • Python數(shù)據(jù)結(jié)構(gòu)之棧、隊列的實現(xiàn)代碼分享

    Python數(shù)據(jù)結(jié)構(gòu)之棧、隊列的實現(xiàn)代碼分享

    這篇文章主要介紹了Python數(shù)據(jù)結(jié)構(gòu)之棧、隊列的實現(xiàn)代碼分享,具有一定參考價值,需要的朋友可以了解下。
    2017-12-12
  • Python引用模塊和查找模塊路徑

    Python引用模塊和查找模塊路徑

    這篇文章主要介紹了Python引用模塊和Python查找模塊路徑的相關(guān)資料,需要的朋友可以參考下
    2016-03-03
  • Python實現(xiàn)提取PDF簡歷信息并存入Excel

    Python實現(xiàn)提取PDF簡歷信息并存入Excel

    作為人力資源部的小伙伴,常常需要把他人投遞的PDF簡歷資料里的關(guān)鍵信息數(shù)據(jù),提取到excel表中匯總,這個時候用Python實現(xiàn)最合適, 快來學(xué)習(xí)一下如何實現(xiàn)吧
    2022-04-04
  • python實現(xiàn)簡單坦克大戰(zhàn)

    python實現(xiàn)簡單坦克大戰(zhàn)

    這篇文章主要為大家詳細(xì)介紹了python實現(xiàn)簡單坦克大戰(zhàn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • 解讀dataframe中有關(guān)inf的處理技巧

    解讀dataframe中有關(guān)inf的處理技巧

    這篇文章主要介紹了解讀dataframe中有關(guān)inf的處理技巧,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Python報錯no?module?named?torch的幾種原因及解決方案

    Python報錯no?module?named?torch的幾種原因及解決方案

    這篇文章主要給大家介紹了關(guān)于Python報錯no?module?named?torch的幾種原因及解決方案,這是小白時常犯的錯,這個報錯一般說明在你電腦當(dāng)前環(huán)境下沒有安裝torch這個模塊,但也有其他情況,需要的朋友可以參考下
    2023-10-10
  • Python中的XML庫4Suite Server的介紹

    Python中的XML庫4Suite Server的介紹

    這篇文章主要介紹了Python中的XML庫4Suite Server,來自于IBM官方網(wǎng)站,需要的朋友可以參考下
    2015-04-04

最新評論

南皮县| 湘潭县| 昌图县| 谢通门县| 卓尼县| 普宁市| 邹城市| 酒泉市| 枝江市| 图木舒克市| 桦南县| 徐汇区| 合山市| 惠州市| 来凤县| 富民县| 股票| 忻城县| 陆河县| 修水县| 彭州市| 济宁市| 桐乡市| 高邑县| 天柱县| 舞钢市| 绥江县| 峡江县| 长岭县| 奎屯市| 英山县| 烟台市| 吐鲁番市| 宁武县| 丹巴县| 土默特左旗| 崇左市| 宁河县| 应城市| 河东区| 铜陵市|