GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • PYTHON CHARTS
  • matplotlib
  • seaborn
  • plotly
  • pandas
  • colors
  • COLORS
  • COLOR PALETTES
  • R CODER
  • R CHARTS
  • Contact
  • Español

This view

  • Original page
  • New address

GeezerVison is showing python-charts.com — Radar chart in matplotlib

Search for a graph

HOME RANKING RADAR CHART MATPLOTLIB

Radar chart in matplotlib

Sample data

Consider the following data for illustration purposes:

# Data
categories = ["Speed", "Power", "Range", "Comfort", "Price"]
values = [4, 3, 5, 4, 2]

Radar chart in matplotlib

A radar chart (or spider chart) compares several numeric variables on axes arranged in a circle, which is why it needs a polar projection instead of the usual cartesian one. Compute an angle per category with numpy, repeat the first value and angle at the end to close the shape, and plot with ax.plot.

import numpy as np
import matplotlib.pyplot as plt

angles = np.linspace(0, 2 * np.pi, len(categories), endpoint = False).tolist()
values_closed = values + values[:1]
angles_closed = angles + angles[:1]

fig, ax = plt.subplots(subplot_kw = dict(projection = "polar"))
ax.plot(angles_closed, values_closed)
ax.set_xticks(angles)
ax.set_xticklabels(categories)

# plt.show()

Radar chart in matplotlib

Fill

Add ax.fill right after ax.plot, using the same closed angles and values, to shade the area under the line.

import numpy as np
import matplotlib.pyplot as plt

angles = np.linspace(0, 2 * np.pi, len(categories), endpoint = False).tolist()
values_closed = values + values[:1]
angles_closed = angles + angles[:1]

fig, ax = plt.subplots(subplot_kw = dict(projection = "polar"))
ax.plot(angles_closed, values_closed)
ax.fill(angles_closed, values_closed, alpha = 0.25)
ax.set_xticks(angles)
ax.set_xticklabels(categories)

# plt.show()

Filled radar chart in matplotlib

Colors

Set color on both plot and fill to change the line and fill color.

import numpy as np
import matplotlib.pyplot as plt

angles = np.linspace(0, 2 * np.pi, len(categories), endpoint = False).tolist()
values_closed = values + values[:1]
angles_closed = angles + angles[:1]

fig, ax = plt.subplots(subplot_kw = dict(projection = "polar"))
ax.plot(angles_closed, values_closed, color = "#C44E52")
ax.fill(angles_closed, values_closed, color = "#C44E52", alpha = 0.25)
ax.set_xticks(angles)
ax.set_xticklabels(categories)

# plt.show()

Colors of a radar chart in matplotlib

Several groups

To compare more than one group, repeat the plot and fill calls for each series on the same polar axes and add a legend.

import numpy as np
import matplotlib.pyplot as plt

angles = np.linspace(0, 2 * np.pi, len(categories), endpoint = False).tolist()
angles_closed = angles + angles[:1]
values_a = values + values[:1]
values_b = [3, 4, 3, 5, 4] + [3]

fig, ax = plt.subplots(subplot_kw = dict(projection = "polar"))
ax.set_xticks(angles)
ax.set_xticklabels(categories)

ax.plot(angles_closed, values_a, label = "Model A")
ax.fill(angles_closed, values_a, alpha = 0.15)
ax.plot(angles_closed, values_b, label = "Model B")
ax.fill(angles_closed, values_b, alpha = 0.15)
ax.legend(loc = "upper right", bbox_to_anchor = (1.3, 1.1))

# plt.show()

Radar chart with several groups in matplotlib

R CODER website
Data Sketches

Data Sketches

A journey of imagination, exploration, and beautiful data visualizations

Buy on Amazon
Better Data Visualizations

Better Data Visualizations

A Guide for Scholars, Researchers, and Wonks

Buy on Amazon

See also

Tables in matplotlib

Tables in matplotlib

Stem plot (lollipop chart) in matplotlib

Stem plot (lollipop chart) in matplotlib

Lollipop chart in plotly

Lollipop chart in plotly

Bar chart in pandas

Bar chart in pandas

Circular barplot in matplotlib

Circular barplot in matplotlib

Radar chart in plotly

Radar chart in plotly

Population pyramid in matplotlib

Population pyramid in matplotlib

Count plot in seaborn

Count plot in seaborn

Bar plot in seaborn

Bar plot in seaborn

Bar chart in plotly

Bar chart in plotly

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.