Python matplotlib生成图片背景透明
来源:互联网 发布:淘宝好评怎么走返利 编辑:程序博客网 时间:2024/05/29 11:07
使用matplotlib生成图片,想要背景透明,而且图例部分也显示透明效果,找到了大概的设置方法,特此记录。
# coding=utf-8# matplotlib背景透明示例图# python 3.5import numpy as npimport matplotlib.pyplot as pltfrom pylab import mplimport scipy.stats as stats# 设置中文字体mpl.rcParams['font.sans-serif'] = ['SimHei']def autolabel(rects): # attach some text labels for rect in rects: height = rect.get_height() # 设置标注文字及位置 ax.text(rect.get_x() + rect.get_width() / 2, 0.03 + height, '%.4f' % height, ha='center', va='bottom')# 数据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 = 3width = 0.5ind = 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('数值')ax.yaxis.grid(True)ax.set_xticks(ind + width * 2.5)ax.set_xticklabels(('P', 'R', 'F'))# 设置图例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') # 设置图例legend背景透明# 给每个数据矩形标注数值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' 图片边界空白紧致, 背景透明效果可能在网页上看不出来,但还是把图片贴上来吧。
0 0
- Python matplotlib生成图片背景透明
- 关于Java生成背景透明的png图片
- png图片生成缩略图——背景透明
- 【转】关于Java生成背景透明的png图片
- android动态生成背景透明带文字的图片
- 设置背景透明图片
- ps图片背景透明
- 图片背景透明处理
- matplotlib图表图片生成
- Python matplotlib 生成图形
- Gdiplus图片背景透明问题
- IE6 图片背景透明 修复
- wince 图片背景透明处理
- ps 透明背景的图片
- 【GIF图片】用PS生成背景透明的GIF图片出现帧叠加的现象
- C#生成透明图片
- Java调整图片大小合并PNG图片生成ICON(保持背景透明)
- 将图片的背景设置为透明
- JS基本语法
- hdu 3549 Flow Problem (最大流—EK—Dinic)
- JS内置对象
- laravel session用法
- LeetCode 312 Burst Balloons (区间dp)
- Python matplotlib生成图片背景透明
- 随便写
- 采集常用的两个函数
- 学习JavaWeb之Servlet_Response
- C#--设计模式之工厂方法模式
- 【框架】[MyBatis]DAO层只写接口,不用写实现类
- 自定义百度网盘分享密码 提取码
- Myeclipse/eclipse开发工具反编译插件JadClpse
- [ 备战NOIP2016 ] 数论