[Python]matplotlib库实现数据可视化之折线图与散点图复习

这次用到的数据是立方数
同时绘制了折线图和散点图,所以效果有叠加

# -*- coding:utf-8 -*-
import matplotlib.pyplot as plt


def main():
    values = list(range(0, 11))
    cubes = [x**3 for x in values]

    plt.plot(values, cubes)
    plt.scatter(values, cubes, c='r', s=40)

    plt.title("Cube of Value", fontsize=24)
    plt.xlabel("Value", fontsize=14)
    plt.ylabel("Cube", fontsize=14)
    plt.tick_params(axis='both', which='both', labelsize=14)

    plt.savefig('cube.png', bbox_inches='tight')


if __name__ == '__main__':
    main()

输出:
[Python]matplotlib库实现数据可视化之折线图与散点图复习_第1张图片
原文链接:https://blog.irow.top/index.php/archives/35/
更多精彩内容,请关注时与空的终点

你可能感兴趣的:(编程,Python)