01.matplotlib helloworld

pip3安装

pip3 install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
import unittest
import matplotlib.pyplot as plt


class MyTestCase(unittest.TestCase):
    def test_demo1(self):
        """hello matplotlib"""
        plt.style.use('classic')
        plt.plot([1, 2, 3], [4, 5, 6])
        # plt.show()
        # 保存图片
        plt.savefig('test.png')

    def test_demo2(self):
        """绘制子图"""
        # 行、列 、编号
        plt.subplot(1, 2, 1)
        plt.plot([1, 2, 3], [4, 5, 6])
        plt.subplot(1, 2, 2)
        plt.plot([1, 2], [1, 2])
        plt.savefig('test_demo2.png')

if __name__ == '__main__':
    unittest.main()

test.png

test_demo2.png

原文地址:https://www.cnblogs.com/fly-book/p/14132776.html