Python中Radar,Barplot,WordCloud,Circilar Barplot图在python中实现
图是这个网站的:https://www.python-graph-gallery.com/
话不多说,直接上代码,不懂直接联系我,私信会及时回复的
Rardar:
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]]))
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
from wordcloud import WordCloud
import matplotlib.pyplot as plt
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")
wordcloud = WordCloud(width=480, height=480).generate(text)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
Circular Barplot
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
%config InlineBackend.figure_format='svg'
df = pd.DataFrame(
{
'Name': ['item ' + str(i) for i in list(range(1, 51)) ],
'Value': np.random.randint(low=10, high=100, size=50)
})
df = df.sort_values(by=['Value'])
plt.figure(figsize=(20,10))
ax = plt.subplot(111, polar=True)
plt.axis('off')
upperLimit = 100
lowerLimit = 30
labelPadding = 4
max = df['Value'].max()
slope = (max - lowerLimit) / max
heights = slope * df.Value + lowerLimit
width = 2*np.pi / len(df.index)
indexes = list(range(1, len(df.index)+1))
angles = [element * width for element in indexes]
angles
bars = ax.bar(
x=angles,
height=heights,
width=width,
bottom=lowerLimit,
linewidth=2,
edgecolor="white",
color="#61a4b2",
)
for bar, angle, height, label in zip(bars,angles, heights, df["Name"]):
rotation = np.rad2deg(angle)
alignment = ""
if angle >= np.pi/2 and angle < 3*np.pi/2:
alignment = "right"
rotation = rotation + 180
else:
alignment = "left"
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'
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 = 0
for feature_name in feature_names:
data_dict[feature_name] = data[:, column]
column += 1
data_dict["target_labels"] = target_labels
pd_data = pd.DataFrame(data_dict)
plt.figure()
parallel_coordinates(pd_data, "target_labels")
plt.show()
Lollipop
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
%config InlineBackend.figure_format='svg'
df = pd.DataFrame({'group':list(map(chr, range(65, 85))), 'values':np.random.uniform(size=20) })
ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)
plt.stem(ordered_df['values'])
plt.xticks( my_range, ordered_df['group'])
plt.show()
|