绘制带有大量文本的图(matplotlib) [英] draw plot with lots of text outside of it (matplotlib)

查看:46
本文介绍了绘制带有大量文本的图(matplotlib)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个点(大小为 8 的向量)和 3 个不同的按位运算(And、Or、Xor),我将每个点和按位运算的结果映射到二维图上.现在我想显示每个点的真实数据本身以及绘图旁边的操作结果(绘图右侧或绘图上方(只要可能或更好)),以便稍后当我想分析结果时,我可以轻松读取数据值.现在我的图像是这样的,您可以看到图例已被剪下,并且我在情节之外没有地方可以写任何东西:

I have 2 points (a vector of size 8) and 3 different bitwise operation (And, Or, Xor) I mapped each point and the result of bitwise operations on the 2D plot. now I want to show each points real data itself and the result of operation beside plot (righ of the plot or above the plot (whenever is possible or it's better)) so later when I want to analysis the result I can read data value easily. right now my image is like this, and you can see the legend is cut off and I have no place outside of plot to write anything:

我想在情节之外显示的文本:

The text I want to show outside of my plot:

P1  P2  And Or  Xor     
0   1   0   1   1   
0   0   0   0   0   
0   0   0   0   0   
0   0   0   0   0   
1   1   1   1   0   
1   1   1   1   0   
1   1   1   1   0   
1   1   1   1   0   

我正在使用的代码:

import numpy as np
import pylab as pl
fig = pl.figure()
ax = fig.add_subplot(111)

ax.plot(p1x, p1y, 'bx', label='Point 1', alpha=.55, markersize=30)
ax.plot(p2x, p2y, 'r+', label='Point 2', alpha=.55, markersize=30)
ax.plot(Andx, Andy, 'go', label='AND', alpha=.45, markersize=10) 
ax.plot(Orx, Ory, 'y<', label='OR', alpha=.45, markersize=10) 
ax.plot(Xorx, Xory, 'ks',  label='XOR', alpha=.45, markersize=10) 
ax.set_title('Bitwise Operation')
ax.set_xlabel('axis X')
ax.set_ylabel('axis Y')
ax.axis([-0.05, 1.05, -0.05, 1.05])
pl.legend(loc='lower left', bbox_to_anchor=(1.02, 0), borderaxespad=0)
pl.show()

推荐答案

您可以使用 add_axes直接控制轴的大小和位置,然后使用文本来添加你想要的文字.例如:

You can use add_axes to directly control the size and location of your axes and then use text to add the text you want. For example:

import numpy as np
import pylab as pl
fig = pl.figure()

ax =  fig.add_axes([0.1, 0.2, 0.4, 0.4])

ax.plot(.1, .2, 'bx', label='Point 1', alpha=.55, markersize=30)
ax.plot(.2, .1, 'r+', label='Point 2', alpha=.55, markersize=30)
ax.plot(.3, .2, 'go', label='AND', alpha=.45, markersize=10) 
ax.plot(.1, .3, 'y<', label='OR', alpha=.45, markersize=10) 
ax.plot(.1, .2, 'ks',  label='XOR', alpha=.45, markersize=10) 
ax.set_title('Bitwise Operation')
ax.set_xlabel('axis X')
ax.set_ylabel('axis Y')
ax.axis([-0.05, 1.05, -0.05, 1.05])
pl.legend(loc='lower left', bbox_to_anchor=(1.02, 0), borderaxespad=0)

data = ('P1  P2  And Or  Xor \n'
'0   1   0   1   1   \n'
'0   0   0   0   0   \n'
'0   0   0   0   0   \n'
'0   0   0   0   0   \n'
'1   1   1   1   0   \n'
'1   1   1   1   0   \n'
'1   1   1   1   0   \n'
'1   1   1   1   0   \n')

pl.text(1.75,0,data)
pl.show()

这篇关于绘制带有大量文本的图(matplotlib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆