栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【无标题】

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【无标题】

Python中Radar,Barplot,WordCloud,Circilar Barplot图在python中实现
  • 图是这个网站的:https://www.python-graph-gallery.com/
  • 话不多说,直接上代码,不懂直接联系我,私信会及时回复的
  • Rardar:
  • Wordcloud
  • Circular Barplot
  • Parallel
  • Lollipop

图是这个网站的: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]]))   #对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
# Libraries
from 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 wrangling
import 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 in list(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 dataset
max = 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 labels
for bar, angle, height, label in zip(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/2 and angle < 3*np.pi/2:
        alignment = "right"
        rotation = rotation + 180
    else: 
        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 = 0
for 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
# libraries
import 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()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/664308.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号