【问题标题】:seaborn to replace a matplotlibseaborn 替换 matplotlib
【发布时间】:2016-08-02 19:25:14
【问题描述】:

我正在尝试用seaborn 制作一个情节,这是我用patplotlib 完成的一个简单情节

 import matplotlib.pyplot as plt
    radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724]
    square = [1.0, 4.0, 9.0, 16.0, 25.0, 36.0]
    plt.plot(radius, area, label='Circle')
    plt.plot(radius, square, marker='o', linestyle='--', color='r', label='Square')
    plt.xlabel('Radius/Side')
    plt.ylabel('Area')
    plt.title('Area of Shapes')
    plt.legend()
    plt.show()

有什么想法吗?

【问题讨论】:

  • 包括IdentationError?

标签: python matplotlib seaborn


【解决方案1】:

像这样使用它,与默认的 matplotlib 绘图相比,你的绘图会更好看:

import seaborn as sb
import matplotlib.pyplot as plt

sb.set_style("darkgrid")
radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724]
square = [1.0, 4.0, 9.0, 16.0, 25.0, 36.0]
plt.plot(radius, area, label='Circle')
plt.plot(radius, square, marker='o', linestyle='--', color='r', label='Square')
plt.xlabel('Radius/Side')
plt.ylabel('Area')
plt.title('Area of Shapes')
plt.legend()
plt.show()

希望这对你有用。请检查缩进。可以找到seaborn的好资源here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 2021-04-23
    • 2020-08-31
    相关资源
    最近更新 更多