鱼C论坛

 找回密码
 立即注册
查看: 3780|回复: 0

python 如何绘制背景透明的图

[复制链接]
发表于 2014-8-28 16:01:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
从MySQL获取数据绘图代码如下,怎样设置所绘制图形的背景是透明的,以突出显示途中的箭头?

from pylab import *
import numpy as np
import matplotlib.pyplot as plt
import time

import matplotlib
matplotlib.use('Agg')

from matplotlib.pyplot import savefig
import MySQLdb
db=MySQLdb.connect("localhost","root","123456789","data")
cursor=db.cursor()
cursor.execute("select * from bydata order by id desc limit 1")
cds=cursor.fetchall()
bo_gao=cds[0][6]
liu_su=cds[0][8]
liu_xiang=cds[0][9]
a=float(bo_gao)
b=float(liu_su)
th=int(liu_xiang)
b
th

plt.xlim(-20,20)
plt.ylim(-20,20)


r=b*np.sin(th*np.pi/180)
r
t=b*np.cos(th*np.pi/180)
t

w=0.9*b*np.sin(th*np.pi/180)
w
q=-1.1*b*np.cos(th*np.pi/180)
q

ax=gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')

ax.set_xticks([])
ax.set_yticks([])

ax.spines['bottom'].set_color('none')
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_color('none')

plt.annotate('',xy=(w,q),xytext=(0,0),arrowprops=dict(facecolor='yellow',shrink=0.05))
plt.annotate('',xy=(r,t),xytext=(2,6),arrowprops=dict(facecolor='red',shrink=0.05))


savefig('D:/wamp/www/www/refresh0826.png')
plt.show()






refresh0826.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-15 14:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表