Skip to content

circlify code: #79

@ctb

Description

@ctb

ref #48

tax_df = pd.read_csv('examples/tax/test.tax-mg.summarized.csv')

tax_df2 = tax_df[tax_df['rank'] == 'species']
tax_df2['name'] = tax_df2['lineage'].apply(lambda x: x.split(';')[-1])

fractions = list(tax_df2['fraction'].tolist())
names = list(tax_df2['name'].tolist())

# compute circle positions
circles = circlify.circlify(
    fractions,
    show_enclosure=False,
    target_enclosure=circlify.Circle(x=0, y=0, r=1)
)

# reverse the order of the circles to match the order of data
circles = circles[::-1]

# Create just a figure and only one subplot
fig, ax = plt.subplots(figsize=(10, 10))

# Title
#ax.set_title('Basic circular packing')

# Remove axes
ax.axis('off')

# Find axis boundaries
lim = max(
    max(
        abs(circle.x) + circle.r,
        abs(circle.y) + circle.r,
    )
    for circle in circles
)
plt.xlim(-lim, lim)
plt.ylim(-lim, lim)

# list of labels
labels = names[::-1]
# print circles
for circle, label in zip(circles, labels):
    x, y, r = circle
    ax.add_patch(plt.Circle((x, y), r, alpha=0.2, linewidth=2))
    plt.annotate(
        label,
        (x, y),
        va='center',
        ha='center'
    )

plt.savefig('/tmp/circles1.png')

produces:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions