Locked lesson.
About this lesson
Let's show how to add Radar Charts to your spreadsheet.
Exercise files
Download this lesson’s related exercise files.
33 - Radar Charts.docx61.5 KB 33 - Radar Charts SOLUTION.docx
58.8 KB
Quick reference
Radar Charts
In this video we'll look at Radar Charts.
When to use
Use this whenever you'd like to add a Radar chart to your spreadsheet.
Instructions
# Import the charts
from openpyxl.chart import Reference, Series, RadarChart
# Create a Chart instance
chart = RadarChart()
# Change the Chart Type:
chart.type = 'filled'
# Delete our y axis
chart.y_axis.delete = True
Hints & tips
- chart = RadarChart()
- chart.type = 'filled'
- chart.y_axis.delete = True
- 00:04 Okay, in this video I want to look at Radar Charts.
- 00:06 So the first thing we want to do is come up here and we need to import this.
- 00:10 So it's RadarChart.
- 00:13 And instead of dealing with our company_salaries,
- 00:15 we need slightly different data for
- 00:16 this one because RadarCharts require a little bit more data.
- 00:19 So I'm going to open up our file radar.xlsx and
- 00:23 then down here at the bottom, let's save this as radar2.
- 00:28 So okay, let's take a look at this file I've created it, and
- 00:32 I've just put it in here in our directory, it's radar.xlsx.
- 00:37 And you can see we've got months of the year, January through December.
- 00:41 And we've got certain products that are let's call this a nursery or something.
- 00:46 Say we've got a nursery business.
- 00:48 So we've got bulbs, seeds, flowers and trees.
- 00:50 And this is just the dollar amount that we sold of each of these and every month.
- 00:55 So the first part of the year we don't sell bulbs because they're not in season.
- 00:58 Same thing with seeds.
- 00:59 The rest of the year we've just got some sort of dummy data.
- 01:03 So we sell $1,300 worth of trees in February for instance, right?
- 01:07 So we want to make a radar graph out of all this stuff.
- 01:10 So, we need to modify our code a little bit.
- 01:15 So our labels, well first off here instead of a ProjectedPieChart,
- 01:20 this is going to be a RadarChart, all right?
- 01:23 So min_column=1, that will stay the same,
- 01:26 min_row=2 that will stay the same but the max_row is going to be 13.
- 01:30 And if we look at our data row quick you could see we want to go to row 13 which
- 01:35 is December.
- 01:36 We also have one, two, three, four, five, columns, we need to change that as well.
- 01:41 So we can go, let's see, this max_row here will need to be 13.
- 01:47 And we also need a max column here, so let's go max_col, and
- 01:52 that's going to be 5, because we want all 5 of those columns in there.
- 01:57 And then we want row 1 through 13, and that will stay the same.
- 02:01 Okay, so in our options down here,
- 02:03 we're going to need to change some of these as well.
- 02:05 So our chart.type will be filled.
- 02:09 And, let's see our chart.title let's call this Nursery Sales,
- 02:16 and we can set a chart.style here.
- 02:19 So let's go on row 26.
- 02:20 Again same thing with this, you can pick all of different numbers and
- 02:23 you just have to go through there sort of play with all of them to see.
- 02:26 And one wierd thing that's a little bit different on this one is,
- 02:33 we need to go chart.y_axis.delete = true.
- 02:38 Just put the nature of this specific chart we want to get rid of the y axis.
- 02:42 So, okay now finally where we want to put this D2 now has stuff in it.
- 02:47 So lets put this in A, I don't know, 18 or something.
- 02:51 Like really push it down, like down here, or maybe we can put it in A15.
- 02:56 Let's put it in A15.
- 02:57 That seems fine.
- 02:59 So, A15, so, okay.
- 03:02 Saving editor as radar2.xlsx and that looks good.
- 03:06 So let's go ahead and save our format.py file.
- 03:10 Head back over here, and let's go Python format.py.
- 03:15 Run this guy, now we can head over here and open up radar2.
- 03:20 And we see this radar chart.
- 03:24 And this is a radar chart and it looks like a radar basically,
- 03:27 is why it's called a radar chart.
- 03:29 And you see we've got bulbs, seeds, flowers and trees.
- 03:32 So if we close this, save it, head back over here and
- 03:37 play with our, chart styles.
- 03:39 We put chart.style 20 for instance, and we're going to run this again.
- 03:46 Open this guy again.
- 03:49 And you'll see different colors here.
- 03:51 And again, you could just sort of go through there and
- 03:53 play with them to see which different colors suit you.
- 03:56 There's not a good guide on this.
- 03:58 The documentation is not very thorough when it comes to those numbers as we've
- 04:01 discussed many times, and that's all there is to it.
- 04:04 So that's all for this video, in the next video, we'll look at donut charts.
Lesson notes are only available for subscribers.