I am using the Pygal to make a bar, and using the Style class to set the style.
There is code:
import requests
import pygal
from pygal.style import Style
# Executing a API call and store the response
url = 'https://api.github.com/search/repositories?
q=language:python&sort=stars'
r = requests.get(url)
print("Status code:", r.status_code)
# Storing the response of API
response_dic = r.json()
print("Total repositories:", response_dic['total_count'])
# About repositories
repo_lists = response_dic['items']
names, stars = [], []
for repo_list in repo_lists:
names.append(repo_list['name'])
stars.append(repo_list['stargazers_count'])
# Visualization
my_style = Style(
title_font_size=24,
label_font_size=14,
major_label_font_size=18,
colors=('#336699',))
my_config = pygal.Config()
my_config.x_label_rotation = 45
my_config.show_legend = False
my_config.truncate_label = 15
my_config.show_y_guides = False
my_config.width = 1000
chart = pygal.Bar(my_config, style=my_style)
chart.title = 'Most-Starred Python Project on Github'
chart.x_labels = names
chart.add('', stars)
chart.render_to_file('python_repos.svg')
Using the Sytle() to create my_style. The property colors is a tuple.
My question is why the comma is necessary in colors=('#336699',)?
How can I understand this?
If I take out the comma, error happened, like this:
Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\Python\Python36\site-
packages\pygal\colors.py", line 107, in parse_color
assert len(color) == 8
AssertionError
[Finished in 3.6s with exit code 1]
I need some help. And thank you for your time!