24小时热门版块排行榜    

查看: 3467  |  回复: 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的回帖

seu-ljc

木虫 (正式写手)

引用回帖:
5楼: Originally posted by aprillf at 2015-04-13 08:46:22
一个图就把subplot()语句去掉...


    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.plot(x, y2,label="y1"
    # Add legend, title and axis labels

    # lgd.get_frame().set_alpha(0.0)


    ax.set_xlabel('x label')
    ax.set_ylabel('y label')   
    legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)


    show()
    fig.savefig('image_output.png',  transparent=True)
  • null


去掉了就显示不了图例了啊
python/matplotlib  图例如何放在外面?-1
6楼2015-04-13 14:35:24
已阅   回复此楼   关注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  图例如何放在外面?-2
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  图例如何放在外面?-3
4楼2015-04-12 16:07:25
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见