24小时热门版块排行榜    

查看: 3153  |  回复: 8
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

seu-ljc

木虫 (正式写手)

[求助] python/matplotlib 图例如何放在外面?已有1人参与

from pylab import *
fig = figure()
x=linspace(0,1,10)
y1=x
y2=x**2
plot(x,y1,'k',linewidth=2,label="y1"
plot(x,y2,'r',linewidth=2,label="y2"
leg=legend(numpoints=1,fontsize=18)
legend(loc='center left', bbox_to_anchor=(1, 0.5))
leg.get_frame().set_alpha(0.0)
grid()
show()
fig.savefig('o.png', transparent=True)

我用了这个命令
legend(loc='center left', bbox_to_anchor=(1, 0.5))

结果变成这样了
python/matplotlib  图例如何放在外面?


请高手支招~多谢~
回复此楼

» 收录本帖的淘贴专辑推荐

source

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cooooldog

铁杆木虫 (著名写手)

ส็็็

引用回帖:
6楼: Originally posted by seu-ljc at 2015-04-13 14:35:24
import matplotlib.pyplot as plt
from pylab import *
# data
x=linspace(0,1,10)
y1=x
y2=x**2

# Plot
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.plot(x, y1,label="y1"
ax. ...

如果这个可以,分数给我偶像aprillf吧
CODE:
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)

fig = plt.figure()
ax = plt.subplot(111)

for i in xrange(5):
    ax.plot(x, i * x, label='$y = %ix$'%i)

# Shrink current axis by 20%
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])

# Put a legend to the right of the current axis
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

plt.show()

ส็็็็็็็็็็็็็็็็็็็็
7楼2015-04-14 11:43:17
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 9 个回答

aprillf

木虫 (正式写手)

【答案】应助回帖

感谢参与,应助指数 +1
看matplotlib的帮助文档即可
http://matplotlib.org/1.3.1/users/legend_guide.html
CODE:
from matplotlib.pyplot import *

subplot(211)
plot([1,2,3], label="test1")
plot([3,2,1], label="test2")
legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
       ncol=2, mode="expand", borderaxespad=0.)

subplot(223)
plot([1,2,3], label="test1")
plot([3,2,1], label="test2")
legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)


show()

2楼2015-04-12 14:55:58
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

seu-ljc

木虫 (正式写手)

引用回帖:
2楼: Originally posted by aprillf at 2015-04-12 14:55:58
看matplotlib的帮助文档即可
http://matplotlib.org/1.3.1/users/legend_guide.html


from matplotlib.pyplot import *

subplot(211)
plot(, label="test1"
plot(, label="test2"
...

这个我看过,现在目前是我要一个图即可,而不是两个图~按这个做出来的效果如下
python/matplotlib  图例如何放在外面?-1
3楼2015-04-12 16:05:34
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

seu-ljc

木虫 (正式写手)

引用回帖:
2楼: Originally posted by aprillf at 2015-04-12 14:55:58
看matplotlib的帮助文档即可
http://matplotlib.org/1.3.1/users/legend_guide.html


from matplotlib.pyplot import *

subplot(211)
plot(, label="test1"
plot(, label="test2"
...

有大块的空白地。。。
python/matplotlib  图例如何放在外面?-2
4楼2015-04-12 16:07:25
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 青年基金会评专家到底是怎么会评的呀?主审专家是不是一般不会改动系统按函评给的顺序 5+4 他山攻玉之石 2024-06-18 18/900 2024-06-20 16:33 by 他山攻玉之石
[精细化工] 试剂价格 +5 旭必上岸 2024-06-17 8/400 2024-06-20 16:25 by 旭必上岸
[考博] 一名额难求啊 +4 pinbo拼搏 2024-06-19 4/200 2024-06-20 16:25 by yueyueyue@
[有机交流] 怎么萃取出锡盐内包裹的化合物 +3 硕六过 2024-06-19 4/200 2024-06-20 15:45 by 2461777831
[找工作] 药学硕士找不到工作,打算去做科研助理了 +10 pom戴墨镜 2024-06-14 23/1150 2024-06-20 15:26 by ase123456
[教师之家] 每次骚扰女学生的都是院系领导,而不是普通教师,小编们要注意措辞正确 +11 zju2000 2024-06-15 13/650 2024-06-20 15:19 by ase123456
[精细化工] 切削液交流群 +5 SZ吴彦祖 2024-06-17 5/250 2024-06-20 12:10 by 毛爱波BBB
[基金申请] 工材口青年基金上会可能性 +8 今晚推荐22 2024-06-19 10/500 2024-06-20 11:00 by 手心里的幸福
[考博] 2025年博士申请,可先做科研助理 +4 limit888 2024-06-18 7/350 2024-06-20 10:23 by 安塔瓦拉多
[基金申请] 太卷了 +14 laoyuefubio 2024-06-17 27/1350 2024-06-20 09:52 by htjwqy
[催化] 镍负载氧化铝的保存问题 8+3 lwn0130 2024-06-15 6/300 2024-06-20 09:00 by lwn0130
[基金申请] 江南大学到瑞士招聘,称取消非升即走,改预聘+长聘 +21 babu2015 2024-06-18 22/1100 2024-06-19 23:03 by feng6531
[基金申请] F口信息学部拿面上,大概需要什么样的成果 +7 _奋黎_ 2024-06-16 18/900 2024-06-19 20:02 by _奋黎_
[基金申请] 面上博士后 +3 jsqy 2024-06-19 3/150 2024-06-19 17:58 by bxwisdom_886
[公派出国] 去英国的小伙伴儿都在哪儿租的房子呀? +7 65syn 2024-06-14 11/550 2024-06-19 10:19 by 65syn
[考博] 2025考博 +8 自强不息a?a 2024-06-15 13/650 2024-06-18 18:12 by 投必得科研顾问
[论文投稿] 论文已接收,但发现修改稿传的是旧版该怎么办? +3 zsq54321 2024-06-15 6/300 2024-06-17 19:45 by wjykycg
[论文投稿] 审稿问题:为什么荧光激发波长和紫外吸收波长差的大? 10+5 sdawege 2024-06-14 10/500 2024-06-17 18:54 by HH-探针
[基金申请] 面青地会评时间 +8 tanjydd 2024-06-15 8/400 2024-06-17 17:08 by 小龙虾2008
[有机交流] ππ堆积会发生在有机溶剂中吗 5+3 zibuyu0420 2024-06-13 4/200 2024-06-14 14:17 by 小肉干
信息提示
请填处理意见