收藏 | Python数据可视化的一些简单总结

Posted 人工智能博士

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了收藏 | Python数据可视化的一些简单总结相关的知识,希望对你有一定的参考价值。

点上方蓝字人工智能算法与Python大数据获取更多干货

在右上方 ··· 设为星标 ★,第一时间获取资源

本文为个人学习笔记记录

近期绘图较多,在画图的时候总结了一些简单的绘图代码,希望能够帮助大家

Spider Plot绘图代码总结

# Import libs
import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt


# Get the data
df=pd.read_csv("AwesomeKings.csv")
print(df)


"""
   #             Name  Attack  Defense  Speed  Range  Health
0  1         Iron Man      83       80     75     70      70
1  2  Captain America      60       62     63     80      80
2  3             Thor      80       82     83    100     100
3  3             Hulk      80      100     67     44      92
4  4      Black Widow      52       43     60     50      65
5  5          Hawkeye      58       64     58     80      65


"""


# Get the data for Iron Man
labels=np.array(["Attack","Defense","Speed","Range","Health"])
stats=df.loc[0,labels].values


# Make some calculations for the plot
angles=np.linspace(0, 2*np.pi, len(labels), endpoint=False)
stats=np.concatenate((stats,[stats[0]]))
angles=np.concatenate((angles,[angles[0]]))


# Plot stuff
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.plot(angles, stats, 'o-', linewidth=2)
ax.fill(angles, stats, alpha=0.25)
ax.set_thetagrids(angles * 180/np.pi, labels)
ax.set_title([df.loc[0,"Name"]])
ax.grid(True)


plt.show()

树状图代码总结

# Import libs
import pandas as pd
from matplotlib import pyplot as plt
from scipy.cluster import hierarchy
import numpy as np


# Read in the dataset
# Drop any fields that are strings
# Only get the first 40 because this dataset is big
df = pd.read_csv('AwesomeKings.csv')
df = df.set_index('Name')
del df.index.name
df = df.drop(["Type 1", "Type 2", "Legendary"], axis=1)
df = df.head(n=40)


# Calculate the distance between each sample
Z = hierarchy.linkage(df, 'ward')


# Orientation our tree
hierarchy.dendrogram(Z, orientation="left", labels=df.index)


plt.show()


热力图代码总结

# Importing libs
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


# Create a random dataset
data = pd.DataFrame(np.random.random((10,6)), columns=["Iron Man","Captain America","Black Widow","Thor","Hulk", "Hawkeye"])


print(data)


# Plot the heatmap
heatmap_plot = sns.heatmap(data, center=0, cmap='gist_ncar')


plt.show()

二维密度图总结

# Importing libs
import seaborn as sns
import matplotlib.pyplot as plt
from scipy.stats import skewnorm


# Create the data
speed = skewnorm.rvs(4, size=50) 
size = skewnorm.rvs(4, size=50)


# Create and shor the 2D Density plot
ax = sns.kdeplot(speed, size, cmap="Reds", shade=False, bw=.15, cbar=True)
ax.set(xlabel='speed', ylabel='size')
plt.show()


多动手才行,实践出真理

---------♥---------

AI博士私人微信,还有少量空位

如何画出漂亮的深度学习模型图?

如何画出漂亮的神经网络图?

一文读懂深度学习中的各种卷积

点个在看支持一下吧

以上是关于收藏 | Python数据可视化的一些简单总结的主要内容,如果未能解决你的问题,请参考以下文章

收藏 | Python数据可视化的一些简单总结

收藏 | Python数据可视化的一些简单总结

50个数据可视化最有价值的图表(附完整Python代码,建议收藏)

50个最有价值的数据可视化图表(推荐收藏)

收藏 | 私藏的30个数据可视化技巧

干货分享 | 看如何用Python数据可视化来分析用户留存率,建议收藏