在命令行上打印
termiplot的Python项目详细描述
术语批
termiplot是一个python 3库,可以满足所有终端打印需求。它的目标是工作 就像matplotlib。
线图
对于线图,termiplot依赖于gnuplot。安装后,代码
importtermiplotastpimportnumpyx=numpy.linspace(0,2*numpy.pi,10)y=numpy.sin(x)fig=tp.figure()fig.plot(x,y,label="data",width=50,height=15)fig.show()
产生
1 +---------------------------------------+
0.8 | ** ** |
0.6 | * ** data ******* |
0.4 | ** |
0.2 |* ** |
0 | ** |
| * |
-0.2 | ** ** |
-0.4 | ** * |
-0.6 | ** |
-0.8 | **** ** |
-1 +---------------------------------------+
0 1 2 3 4 5 6 7
表格
termiplot为表格打印提供了许多选项。最基本的例子是 代码
importtermiplotastpimportnumpynumpy.random.seed(0)data=numpy.random.rand(5,2)fig=tp.figure()fig.table(data)fig.show()
产生
您可以控制边框样式、填充、对齐和各种其他属性。为了 示例,
importtermiplotastpdata=[[["a","bb","ccc"]],[[1,2,3],[613.23236243236,613.23236243236,613.23236243236]],]fig=tp.figure()fig.table(data,border_style="thin",force_ascii=True,padding=(0,1),alignment="lcr")fig.show()
产生
+-----------------+-----------------+-----------------+
| a | bb | ccc |
+=================+=================+=================+
| 1 | 2 | 3 |
+-----------------+-----------------+-----------------+
| 613.23236243236 | 613.23236243236 | 613.23236243236 |
+-----------------+-----------------+-----------------+
见
^{
水平直方图
importtermiplotastpimportnumpynumpy.random.seed(123)sample=numpy.random.normal(size=1000)counts,bin_edges=numpy.histogram(sample)fig=tp.figure()fig.hist(counts,bin_edges,orientation="horizontal",force_ascii=False)fig.show()
产生
垂直直方图
importtermiplotastpimportnumpynumpy.random.seed(123)sample=numpy.random.normal(size=1000)counts,bin_edges=numpy.histogram(sample,bins=40)fig=tp.figure()fig.hist(counts,bin_edges,grid=[15,25],force_ascii=False)fig.show()
产生
安装
termiplot是available from the Python Package Index,所以只需
pip3 install -U termiplot
安装或升级。使用sudo -H
作为根用户或--user
选项安装
安装在pip3
中。
测试
要运行termiplot单元测试,请签出此存储库并键入
pytest
分布
创建新版本
把
__version__
号撞一下,发布到pypi并在github上标记:
$ make publish
许可证
termiplot在MIT license下发布。