import numpy as np
import matplotlib.pyplot as plt
import matplotlib
%config InlineBackend.figure_format='svg'#矢量图设置
matplotlib.rcParams['font.family']='SimHei'
matplotlib.rcParams['font.sans-serif']=['SimHei']
labels = np.array(['综合','KDA','发育','推进','生存','输出'])
data = np.concatenate((data,[data[0]]))
angles = np.concatenate((angles,[angles[0]]))
labels=np.concatenate((labels,[labels[0]]))#对labels进行封闭
nAttr =6
data = np.array([7,5,6,9,8,7])
angles = np.linspace(0,2*np.pi,nAttr,endpoint=False)
data = np.concatenate((data,[data[0]]))
angles = np.concatenate((angles,[angles[0]]))
fig = plt.figure(facecolor="white")
plt.subplot(111,polar=True)
plt.plot(angles,data,'bo-',color ='g',linewidth=2)
plt.fill(angles,data,facecolor='g',alpha=0.25)
plt.thetagrids(angles*180/np.pi,labels)
plt.figtext(0.52,0.95,'DOTA能力值雷达图',ha='center')
plt.grid(True)
plt.show()
Wordcloud
# Librariesfrom wordcloud import WordCloud
import matplotlib.pyplot as plt
# Create a list of word
text=("Python Python Python Matplotlib Matplotlib Seaborn Network Plot Violin Chart Pandas Datascience Wordcloud Spider Radar Parrallel Alpha Color Brewer Density Scatter Barplot Barplot Boxplot Violinplot Treemap Stacked Area Chart Chart Visualization Dataviz Donut Pie Time-Series Wordcloud Wordcloud Sankey Bubble")# Create the wordcloud object
wordcloud = WordCloud(width=480, height=480).generate(text)# Display the generated image:
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
Circular Barplot
# import pandas for data wranglingimport pandas as pd
import matplotlib.pyplot as plt
import numpy as np
%config InlineBackend.figure_format='svg'#矢量图设置# Build a dataset
df = pd.DataFrame({'Name':['item '+str(i)for i inlist(range(1,51))],'Value': np.random.randint(low=10, high=100, size=50)})# Reorder the dataframe
df = df.sort_values(by=['Value'])# initialize the figure
plt.figure(figsize=(20,10))
ax = plt.subplot(111, polar=True)
plt.axis('off')# Constants = parameters controling the plot layout:
upperLimit =100
lowerLimit =30
labelPadding =4# Compute max and min in the datasetmax= df['Value'].max()# Let's compute heights: they are a conversion of each item value in those new coordinates# In our example, 0 in the dataset will be converted to the lowerLimit (10)# The maximum will be converted to the upperLimit (100)
slope =(max- lowerLimit)/max
heights = slope * df.Value + lowerLimit
# Compute the width of each bar. In total we have 2*Pi = 360°
width =2*np.pi /len(df.index)# Compute the angle each bar is centered on:
indexes =list(range(1,len(df.index)+1))
angles =[element * width for element in indexes]
angles
# Draw bars
bars = ax.bar(
x=angles,
height=heights,
width=width,
bottom=lowerLimit,
linewidth=2,
edgecolor="white",
color="#61a4b2",)# Add labelsfor bar, angle, height, label inzip(bars,angles, heights, df["Name"]):# Labels are rotated. Rotation must be specified in degrees :(
rotation = np.rad2deg(angle)# Flip some labels upside down
alignment =""if angle >= np.pi/2and angle <3*np.pi/2:
alignment ="right"
rotation = rotation +180else:
alignment ="left"# Finally add the labels
ax.text(
x=angle,
y=lowerLimit + bar.get_height()+ labelPadding,
s=label,
ha=alignment,
va='center',
rotation=rotation,
rotation_mode="anchor")
Parallel
import pandas as pd
import matplotlib.pyplot as plt
from pandas.plotting import parallel_coordinates
from sklearn import datasets
%config InlineBackend.figure_format='svg'#矢量图设置# 使用pandas中的parallel_coordinates可视化高维数据# 导入数据
data_origin = datasets.load_iris()# 处理数据# 先把数据提出来
data = data_origin["data"]# 处理类标签数据
target = data_origin["target"]
target_names = data_origin["target_names"]
target_labels =[]for class_num in target:
target_labels.append(target_names[class_num])
feature_names = data_origin["feature_names"]# 合成字典
data_dict ={}
column =0for feature_name in feature_names:
data_dict[feature_name]= data[:, column]
column +=1
data_dict["target_labels"]= target_labels
# 合成dataFrame
pd_data = pd.DataFrame(data_dict)# 画图
plt.figure()
parallel_coordinates(pd_data,"target_labels")
plt.show()
Lollipop
# librariesimport pandas as pd
import matplotlib.pyplot as plt
import numpy as np
%config InlineBackend.figure_format='svg'#矢量图设置# Create a dataframe
df = pd.DataFrame({'group':list(map(chr,range(65,85))),'values':np.random.uniform(size=20)})#定义数据从A-# Reorder it based on the values:
ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)# Make the plot
plt.stem(ordered_df['values'])
plt.xticks( my_range, ordered_df['group'])
plt.show()