#๐Ÿ”’ What library/tool was used to create such a radar plot?

37 messages ยท Page 1 of 1 (latest)

loud marten
#

Came across this figure in a paper and I would like to reproduce it. However, when I tried to reproduce it with plotly or matplotlib+seaborn I cannot seem to do it for the life of me (might be a skill issue)... Does anybody know what library was used to create a radar plot like this, or if this was even done in Python?

alpine viperBOT
#

@loud marten

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

humble apex
#

it should be doable with matplotlib or plotly, if you can share some data to be plotted and your attempts it would be helpful

humble apex
loud marten
#

So far I have been able to make a radar plot that has the right shape and layout etc. But I cannot seem to get the colors clear and nicely blended like the original. The data itself is a small dataframe with some median values based on a clustering where the label is the 5_attr_adj column. I use this label to determine the color with my viridis color map

#

This is how it looks in my notebook rn

#

This is the current code:

df = publicly_available_medians_gdf.set_index("5_attr_adj")
attrs = df.columns.tolist()
angles = np.linspace(0, 2 * np.pi, len(attrs), endpoint=False).tolist()
angles += angles[:1]

fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))
ax.set_theta_offset(np.pi / 2)
ax.set_theta_direction(-1)

viridis_frequently_used = plt.get_cmap("viridis", len(dim_red_results_publicly_available["5_attr_adj"].unique()))
colors = viridis_frequently_used(np.linspace(0, 1, len(df)))
for i, (_, row) in enumerate(df.iterrows()):
    values = row.tolist()
    values += values[:1]
    ax.plot(angles, values, color=colors[i], alpha=0.7, linewidth=2)
    ax.fill(angles, values, color=colors[i], alpha=0.1)

y_ticks = [0.2, 0.4, 0.6, 0.8, 1.0]
ax.set_yticks(y_ticks)
ax.set_yticklabels([str(y) for y in y_ticks], fontsize=10, color="gray")
ax.set_xticks(angles[:-1])
ax.set_xticklabels(attrs, fontsize=10)
ax.yaxis.grid(True)
plt.show()
humble apex
#

would you mind sharing the data as well? just so it's easier to run the code

loud marten
#

Was about to make the export ๐Ÿ˜‰

humble apex
#

csv files can be shared in this chat ๐Ÿ™‚

loud marten
#

aah even better, 1 sec

alpine viperBOT
humble apex
#

yeah ๐Ÿ™‚ what is publicly_available_medians_gdf and dim_red_results_publicly_available?

#

got your image

loud marten
#

Yeah thats what I get rn too, just need to know how to blend these colors and make the transitions nicer

humble apex
#

just setting linewidth=0 already makes this which I think is closer to what you were looking for

loud marten
#

Thank you, I was getting tunnel vision

#

This looks better already

humble apex
#

choosing the "RdBu_r" colormap gives

loud marten
#

Wish that I could use that, but I am stuck with Viridis

humble apex
#

why?

#

so something like this?

loud marten
#

I have to reproduce for a uni project, but the prof prefers specific color maps

loud marten
humble apex
#

or maybe this is better, you can see more of the lines in the yellow

#

alpha=0.3

loud marten
#

I think that is perfect, thank you, and more resemblance and it might become plagiarism ๐Ÿ˜…

humble apex
#

gl with your project ๐Ÿ™‚

loud marten
#

thank you, you're a lifesaver! really needed that 2nd pair of eyes

humble apex
#
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

publicly_available_medians_gdf = pd.read_csv("radardata.csv")

df = publicly_available_medians_gdf.set_index("5_attr_adj")
attrs = df.columns.tolist()
angles = np.linspace(0, 2 * np.pi, len(attrs), endpoint=False).tolist()
angles += angles[:1]

fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))
ax.set_theta_offset(np.pi / 2)
ax.set_theta_direction(-1)

viridis_frequently_used = plt.get_cmap("viridis", len(publicly_available_medians_gdf["5_attr_adj"].unique()))
colors = viridis_frequently_used(np.linspace(0, 1, len(df)))
for i, (_, row) in enumerate(df.iterrows()):
    values = row.tolist()
    values += values[:1]
    ax.fill(angles, values, color=colors[i], alpha=0.3)

y_ticks = [0.2, 0.4, 0.6, 0.8, 1.0]
ax.set_yticks(y_ticks)
ax.set_yticklabels([str(y) for y in y_ticks], fontsize=10, color="gray")
ax.set_xticks(angles[:-1])
ax.set_xticklabels(attrs, fontsize=10)
ax.yaxis.grid(True)
plt.show()
alpine viperBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.