Scale text size with size of box in crypto/ov/hm (#2278)

* Updated text size so it scales with size of box

* fix linting

Co-authored-by: minhhoang1023 <40023817+minhhoang1023@users.noreply.github.com>
Co-authored-by: Chavithra <chavithra@gmail.com>
Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com>
This commit is contained in:
soggyomelette
2022-08-15 09:41:28 +01:00
committed by GitHub
parent 0f01b8437d
commit f347223fdb

View File

@@ -90,11 +90,26 @@ def display_crypto_heatmap(
squarify.plot(
df["market_cap"],
label=df_copy["symbol"],
alpha=0.8,
color=colors,
text_kwargs={"color": "black", "size": 8},
)
text_sizes = squarify.normalize_sizes(df["market_cap"], 100, 100)
rects = squarify.squarify(text_sizes, 0, 0, 100, 100)
for la, r in zip(df_copy["symbol"], rects):
x, y, dx, dy = r["x"], r["y"], r["dx"], r["dy"]
ax.text(
x + dx / 2,
y + dy / 2,
la,
va="center",
ha="center",
color="black",
size=(
text_sizes[df_copy.index[df_copy["symbol"] == la].tolist()[0]]
** 0.5
* 0.8
),
)
ax.set_title(f"Top {top} Cryptocurrencies {category_str}")
ax.set_axis_off()