如何制作嵌套比例面积图(圆圈)?

编程入门 行业动态 更新时间:2024-10-26 21:28:12
本文介绍了如何制作嵌套比例面积图(圆圈)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在寻找python中可以用来在圈子中绘制嵌套比例面积图的任何内容。最好使用matplotlib构建(或在其之上)。以下是此类绘图的示例供您参考:

I'm looking for anything in python that I can use to do a nested proportional area chart in circles. Preferably something built with (or on top of) matplotlib. Here's an example of what such plot looks like for reference:

推荐答案

一个嵌套的圆形图,其中圆形面积与数据成比例,如下所示。 它将使用排序后的列表或数据数组以及可选的相应标签作为输入,并绘制几个圆。

A nested circle diagram, where the circle area is proportional to the data could look as follows. It would take a sorted list or array of data and optionally the respective labels as input and plot a couple of circles.

import numpy as np import matplotlib.pyplot as plt from matplotlib.collections import PatchCollection def nested_circles(data, labels=None, c=None, ax=None, cmap=None, norm=None, textkw={}): ax = ax or plt.gca() data = np.array(data) R = np.sqrt(data/data.max()) p = [plt.Circle((0,r), radius=r) for r in R[::-1]] arr = data[::-1] if c is None else np.array(c[::-1]) col = PatchCollection(p, cmap=cmap, norm=norm, array=arr) ax.add_collection(col) ax.axis("off") ax.set_aspect("equal") ax.autoscale() if labels is not None: kw = dict(color="white", va="center", ha="center") kw.update(textkw) ax.text(0, R[0], labels[0], **kw) for i in range(1, len(R)): ax.text(0, R[i]+R[i-1], labels[i], **kw) return col

用法可能看起来像

data = [1,3,4,5,6] labels = list("ABCDE") nested_circles(data, labels=labels, cmap="copper", textkw=dict(fontsize=14)) plt.show()

如果您想要其他颜色编码,请使用 c 参数并提供另一个列表值,例如

If you want a different colorcoding, take the c argument and supply another list of values, e.g.

data = [1,3,4,5,6] labels = list("ABCDE") codes = [5,3,1,4,2] circles = nested_circles(data, labels=labels, c=codes, cmap="plasma", textkw=dict(color="black", fontsize=14)) plt.colorbar(circles, label="Codes") plt.title("Diagram") plt.show()

更多推荐

如何制作嵌套比例面积图(圆圈)?

本文发布于:2023-07-18 05:10:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   圆圈   比例   面积

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!