当前位置: 首页 > news >正文

怎么给自己喜欢的人做网站介绍网络营销的短文

怎么给自己喜欢的人做网站,介绍网络营销的短文,列表网推广收费标准,同时做几个网站的seo比较(六)利用python绘制径向柱图 径向柱图(Circular Barplot)简介 径向柱图基于同心圆网格来绘制条形图,虽然不如普通条形图表达准确,但却有抓人眼球的效果。其衍生的南丁格尔玫瑰图则广为人知。 快速绘制…

比较(六)利用python绘制径向柱图

径向柱图(Circular Barplot)简介

1

径向柱图基于同心圆网格来绘制条形图,虽然不如普通条形图表达准确,但却有抓人眼球的效果。其衍生的南丁格尔玫瑰图则广为人知。

快速绘制

  1. 基于matplotlib

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.cm as cmnp.random.seed(0)  # 设置随机种子为0# 自定义数据
    df = pd.DataFrame({'Name': ['item ' + str(i) for i in list(range(1, 51)) ],'Value': np.random.randint(low=10, high=100, size=50)})# 初始化布局-极坐标图
    plt.figure(figsize=(10,8))
    ax = plt.subplot(111, polar=True)# 移除网格
    plt.axis('off')# 坐标限制
    upperLimit = 100
    lowerLimit = 30# 计算极值
    max_value = df['Value'].max()# 数据缩放
    slope = (max_value - lowerLimit) / max_value
    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",)
    

    2

定制多样化的径向柱图

自定义径向柱图一般是结合使用场景对相关参数进行修改,并辅以其他的绘图知识。参数信息可以通过官网进行查看,其他的绘图知识则更多来源于实战经验,大家不妨将接下来的绘图作为一种学习经验,以便于日后总结。

  1. 添加标签

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.cm as cmnp.random.seed(0)  # 设置随机种子为0# 自定义数据
    df = pd.DataFrame({'Name': ['item ' + str(i) for i in list(range(1, 51)) ],'Value': np.random.randint(low=10, high=100, size=50)})# 初始化布局-极坐标图
    plt.figure(figsize=(10,8))
    ax = plt.subplot(111, polar=True)# 移除网格
    plt.axis('off')# 坐标限制
    upperLimit = 100
    lowerLimit = 30# 计算极值
    max_value = df['Value'].max()# 数据缩放
    slope = (max_value - lowerLimit) / max_value
    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",
    )# 标签和bar的间距定义
    labelPadding = 4# 添加标签
    for bar, angle, height, label in zip(bars,angles, heights, df["Name"]):# 弧度转化:将弧度转为度,如np.pi/2->90rotation = np.rad2deg(angle)# 颠倒一部分标签,方便查看alignment = ""if angle >= np.pi/2 and angle < 3*np.pi/2:alignment = "right"rotation = rotation + 180else: alignment = "left"# 通过text函数添加标签ax.text(x=angle, y=lowerLimit + bar.get_height() + labelPadding, s=label, ha=alignment, va='center', rotation=rotation, rotation_mode="anchor") 
    

    3

  2. 引申-简单绘制南丁格尔玫瑰图

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.cm as cmnp.random.seed(0)  # 设置随机种子为0# 自定义数据
    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=(10,8))
    ax = plt.subplot(111, polar=True)
    plt.axis('off')# 坐标限制
    upperLimit = 100
    lowerLimit = 30# 高度
    heights = df.Value
    # 计算每个条形的宽度
    width = 2*np.pi / len(df.index)# 颜色
    cmap = cm.RdYlGn
    # 归一化
    norm_heights = (heights - np.min(heights)) / (np.max(heights) - np.min(heights))
    # 颜色映射到heights
    colors = cmap(norm_heights)# 计算角度
    indexes = list(range(1, len(df.index)+1))
    angles = [element * width + 0.5*np.pi for element in indexes] # 指定从0开始逆时针旋转# 添加条形图
    bars = ax.bar(x=angles, height=heights, width=width, bottom=lowerLimit,linewidth=2, edgecolor="white",color=colors,
    )# 标签和bar的间距定义
    labelPadding = 4# 添加标签
    for bar, angle, height, label in zip(bars,angles, heights, df["Name"]):# 弧度转化:将弧度转为度,如np.pi/2->90rotation = np.rad2deg(angle)# 颠倒一部分标签,方便查看alignment = ""if angle >= np.pi/2 and angle < 3*np.pi/2:alignment = "right"rotation = rotation + 180else: alignment = "left"# 通过text函数添加标签ax.text(x=angle, y=lowerLimit + bar.get_height() + labelPadding, s=label, ha=alignment, va='center', rotation=rotation, rotation_mode="anchor")
    

    4

  3. 分组径向柱图

    import matplotlib.pyplot as plt
    import numpy as np
    import pandas as pdrng = np.random.default_rng(123) # 随机种子# 自定义数据
    df = pd.DataFrame({"name": [f"item {i}" for i in range(1, 51)],"value": rng.integers(low=30, high=100, size=50),"group": ["A"] * 10 + ["B"] * 20 + ["C"] * 12 + ["D"] * 8
    })# 自定义函数,将上述的弧度转换、添加标签抽象成函数
    def get_label_rotation(angle, offset):'''输入弧度和偏移量,返回对应的角度rotation以及对齐方式alignment'''rotation = np.rad2deg(angle + offset)if angle <= np.pi:alignment = "right"rotation = rotation + 180else: alignment = "left"return rotation, alignmentdef add_labels(angles, values, labels, offset, ax):# 标签与bar的间距padding = 4# 迭代每个弧度、bar值和标签for angle, value, label, in zip(angles, values, labels):angle = angle# 获取角度和对齐方式rotation, alignment = get_label_rotation(angle, offset)# 添加文本标签ax.text(x=angle, y=value + padding, s=label, ha=alignment, va="center", rotation=rotation, rotation_mode="anchor") 
    
    # 自定义基础变量
    GROUP = df["group"].values # 分组
    GROUPS_SIZE = [len(i[1]) for i in df.groupby("group")] # 每组的数量
    COLORS = [f"C{i}" for i, size in enumerate(GROUPS_SIZE) for _ in range(size)] # 每组使用不同的颜色# bar的值与标签
    VALUES = df["value"].values
    LABELS = df["name"].values# 偏移量:默认从0开始,指定成从90度位置开始
    OFFSET = np.pi / 2# bar宽度、角度
    PAD = 3 # 每组末尾添加3个空白bar
    ANGLES_N = len(VALUES) + PAD * len(np.unique(GROUP))
    ANGLES = np.linspace(0, 2 * np.pi, num=ANGLES_N, endpoint=False)
    WIDTH = (2 * np.pi) / len(ANGLES) # 2pi/条形数量得到每个条形宽度# 获取索引
    offset = 0
    IDXS = []
    for size in GROUPS_SIZE:IDXS += list(range(offset + PAD, offset + size + PAD))offset += size + PAD# 初始化极坐标图
    fig, ax = plt.subplots(figsize=(10, 8), subplot_kw={"projection": "polar"})# 指定偏移量
    ax.set_theta_offset(OFFSET)# 设置范围
    ax.set_ylim(-100, 100)# 移除边框
    ax.set_frame_on(False)# 移除网格和轴刻度
    ax.xaxis.grid(False)
    ax.yaxis.grid(False)
    ax.set_xticks([])
    ax.set_yticks([])# 添加条形图
    ax.bar(ANGLES[IDXS], VALUES, width=WIDTH, color=COLORS, edgecolor="white", linewidth=2
    )# 添加标签
    add_labels(ANGLES[IDXS], VALUES, LABELS, OFFSET, ax)# 额外添加分组标签
    offset = 0 # 重置为0
    for group, size in zip(["A", "B", "C", "D"], GROUPS_SIZE):# 在条形图下添加线条x1 = np.linspace(ANGLES[offset + PAD], ANGLES[offset + size + PAD - 1], num=50)ax.plot(x1, [-5] * 50, color="#333333")# 添加分组标签ax.text(np.mean(x1), -20, group, color="#333333", fontsize=14, fontweight="bold", ha="center", va="center")# 添加参考线:[20, 40, 60, 80]x2 = np.linspace(ANGLES[offset], ANGLES[offset + PAD - 1], num=50)ax.plot(x2, [20] * 50, color="#bebebe", lw=0.8)ax.plot(x2, [40] * 50, color="#bebebe", lw=0.8)ax.plot(x2, [60] * 50, color="#bebebe", lw=0.8)ax.plot(x2, [80] * 50, color="#bebebe", lw=0.8)offset += size + PAD
    

    5

总结

以上通过matplotlib结合极坐标绘制基本的径向柱图,并结合相关绘图方法绘制南丁格尔玫瑰图和分组径向柱图。

共勉~

http://www.fp688.cn/news/158690.html

相关文章:

  • 自学广告设计该怎么入手seo网络营销招聘
  • 宿州网站建设工作室搜索引擎营销的特点是
  • 个人简历网页设计代码网站seo推广优化教程
  • 崇明建设机械网站郑州免费做网站
  • wordpress用户插件seo外链建设的方法有
  • 动漫采集WordPress郑州seo团队
  • 漳州微信网站开发电商网络推广怎么做
  • 可信赖的南昌网站制作临沂百度联系方式
  • 网站是怎样建立的流程是什么app推广项目从哪接一手
  • 室内设计软件培训关键词快速排名seo怎么优化
  • wordpress做x站主题windows优化大师要钱
  • 做网站语言学什么企业网站建设论文
  • 做特殊原产地证的网站推广普通话手抄报内容资料
  • 北京建网站软件新人跑业务怎么找客户
  • 好看的网站首页图片百度高级搜索指令
  • 外贸soho做网站怎么做就在刚刚武汉宣布最新消息
  • 南通网站维护seo搜索引擎优化薪酬
  • 商业网站在规划与设计时应着重考虑哪些因素seo流量软件
  • 建网站申请百度seo怎么操作
  • 贵州建设厅监理协会网站企业网站设计代码
  • 做网站跟网站设计的区别汕头seo全网营销
  • 建设学校网站前的需求分析报告网站优化推广服务
  • 视频网站是用什么框架做的可以搜索国外网站的搜索引擎
  • 深圳做网站qq营销软件
  • 做网站昆明营销
  • 景德镇做网站白城seo
  • 网站建设走无形资产上海网络推广渠道
  • 网站建设公司 南京深圳网络推广哪家比较好
  • 龙湖网站建设google adwords
  • 北京名片设计制作济南网站优化排名