Visualize.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:BlueLines 作者: JacksYou 项目源码 文件源码
def scatter_crimes_population():
    """creates a scatter plot using the values of Population and Crimes Per 100000.
    iterates through the database and reads all the data in the given headers and creates plots for each data point
    """
    x = df["Number of Crimes"].values
    y = df["Population"].values
    assert len(x) == len(y)
    df["Crimes Per 100000"] = np.array([(x[i] / y[i]) * 100000.0 for i in range(len(x))], dtype="float32")

    ax = df.plot.scatter(y="Population", x="Crimes Per 100000")

    for index, row in df.iterrows():
        ax.annotate(row["Community Name"], (row["Crimes Per 100000"], row["Population"]),
                    size=7,
                    color='darkslategrey')

    x = df["Crimes Per 100000"].values
    y = df["Population"].values

    m, b = np.polyfit(x, y, 1)
    line = plt.plot(x, m * x + b, 'b--')
    plt.setp(line, color='orange', alpha=0.5, linewidth=2.0)
    plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号