Beispiel #1
0
def render_svg(data_dicts):
    """Render data to svg."""
    names, plot_dicts = [], []
    for data_dict in data_dicts:
        names.append(data_dict['title'])

        plot_dict = {
            'value': data_dict['comments'],
            'label': data_dict['title'],
            'xlink': data_dict['link'],
        }
        plot_dicts.append(plot_dict)

    # Make visualization.
    my_style = LS('#333366', base_style=LCS)
    my_style.title_font_size = 24
    my_style.label_font_size = 14
    my_style.major_label_font_size = 18

    my_config = pygal.Config()
    my_config.x_label_rotation = 45
    my_config.show_legend = False
    my_config.tuncate_label = 15
    my_config.show_y_guides = False
    my_config.width = 1000

    chart = pygal.Bar(my_config, style=my_style)
    chart.title = 'Most-Active discussion on Hacker News.'
    chart.x_labels = names

    chart.add('', plot_dicts)
    chart.render_to_file('discussion.svg')
def generate_rating_file(lang):
    url = 'https://api.github.com/search/repositories?q=language:' + str(
        lang) + '&sort=starts'
    r = requests.get(url)
    response_dict = r.json()
    repo_dicts = response_dict['items']
    names, stars = [], []

    for repo_dict in repo_dicts:
        names.append(repo_dict['name'])
        stars.append(repo_dict['stargazers_count'])

    my_style = LS('#333366', base_style=DCS)
    my_style.title_font_size = 24
    my_style.label_font_size = 14
    my_style.major_label_font_size = 18

    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 ' + str(lang) + ' Projects on GitHub'
    chart.x_labels = names
    chart.add(' ', stars)
    return chart.render_to_file('visualize/static/visualize/repos.svg')
Beispiel #3
0
def render_lang_repo(lang):
    """Render language repo to svg."""
    # Make an API call and store the response.
    url = 'https://api.github.com/search/repositories?q=language:%s&sort=stars' % lang
    r = requests.get(url)
    print('Status code:', r.status_code)

    # Store API response in a variable.
    response_dict = r.json()
    print('Total repositories:', response_dict['total_count'])

    # Explore information about the repositories.
    repo_dicts = response_dict['items']

    names, plot_dicts = [], []
    for repo_dict in repo_dicts:
        names.append(repo_dict['name'])

        # Get the project description, if one is available.
        description = repo_dict['description']
        if not description:
            description = 'No description provided.'

        plot_dict = {
            'value': repo_dict['stargazers_count'],
            'label': str(description),
            'xlink': repo_dict['html_url'],
        }
        plot_dicts.append(plot_dict)

    # Make visualization.
    my_style = LS('#333366', base_style=LCS)
    my_style.title_font_size = 24
    my_style.label_font_size = 14
    my_style.major_label_font_size = 18

    my_config = pygal.Config()
    my_config.x_label_rotation = 45
    my_config.show_legend = False
    my_config.tuncate_label = 15
    my_config.show_y_guides = False
    my_config.width = 1000

    chart = pygal.Bar(my_config, style=my_style)
    chart.title = 'Most-Starred %s Projects on GitHub' % lang.title()
    chart.x_labels = names

    chart.add('', plot_dicts)
    chart.render_to_file('%s_repos.svg' % lang)
Beispiel #4
0
    def likes_chart():

        """
            Calculates the average likes and dislikes of each cuisine group
        """

        # apply custom style to graph
        dark_blue_style = LightenStyle('#004466')

        # create chart type, labels, heading
        bar_chart = pygal.Bar(fill=True, interpolate='cubic', style=dark_blue_style, tooltip_border_radius=10, legend_at_bottom=True)
        bar_chart.title = 'Average Likes / Dislikes per Cuisine'
        bar_chart.x_labels = ['Likes', 'Dislikes']

        # query db for likes / dislikes and group by cuisine
        cursor = db.recipes.aggregate([{"$group": {"_id": "$filters.cuisine", "likes": {"$avg": '$users.likes'}, "dislikes": {"$avg": '$users.dislikes'}}}])

        # add a new bar to the graph for each group
        # dislikes are inverted for the bar chart visual aspect
        for item in cursor:
            if item['_id'] not in Graphs.unwanted_cuisines:
                bar_chart.add(item['_id'], [round(item['likes'], 0), round(item['dislikes'] * -1, 0)])

        # render as data uri
        return bar_chart.render_data_uri()
Beispiel #5
0
def construction_graph(names, plot_dicts):
    # Построение визуализации.
    my_style = LS('#333366', base_style=LCS)
    my_style.title_font_size = 24
    my_style.label_font_size = 14
    my_style.major_label_font_size = 18

    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 Projects on GitHub'
    chart.x_labels = names

    chart.add('', plot_dicts)
    chart.render_to_file('python_repos.svg')
def make_visualization(names,plot_dicts):
	"""可视化"""
	my_style = LS("#333366",base_style = LCS)
	my_style.title_font_size = 24
	my_style.lable_font_size = 14
	my_style.major_lable_font_size = 18
	
	my_config = pygal.Config()
	my_config.x_label_rotation = 45#让标签绕x轴旋转45度(x_label_rotation=45 )
	my_config.show_legend = False#隐藏图例(show_legend=False )
	my_config.truncate_label = 15#将较长的项目名缩短为15个字符
	my_config.show_y_guides = False #隐藏图表中的水平线
	my_config.width = 1000#自定义宽度
	
	chart = pygal.Bar(my_config,style = my_style)
	chart.title = 'Most-Starred Python Projects on GitHub'
	chart.x_labels = names
	chart.add('',plot_dicts)
	chart.render_to_file('refactor_python_repos.svg')
Beispiel #7
0
def make_visualization(names, plot_dicts):
    """Make visualization of most popular repositories."""
    my_style = LS('#333366', base_style=LCS)
    my_style.title_font_size = 24
    my_style.label_font_size = 14
    my_style.major_label_font_size = 18

    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 Projects on GitHub'
    chart.x_labels = names

    chart.add('', plot_dicts)
    chart.render_to_file('python_repos.svg')
Beispiel #8
0
def graphs(weather_dict, dates):
    '''
    This function takes weather data and outputs graphs for temperature, humidity and wind speeds.
    input:
    weather_dict = weather dictionary with relevant data
    dates = a list of dates, each date is a key for the dictionary
    output:
    graph = a list of three graphs, one each for temperature, humidity and windspeed, for each day.
            e.g. [[temp, humid, wind], [temp, humid, wind], etc...]

    '''
    graph = []
    for date in dates:
        temp_style = LightenStyle('#46C5EA', base_style=LightColorizedStyle)
        temp_chart = pygal.StackedLine(fill=True,
                                       interpolate='cubic',
                                       style=temp_style)
        temp_chart.title = 'Temperature in degrees celsius'
        temp_chart.x_labels = map(str, weather_dict[date]['times'])
        temp_chart.add('Temperature', weather_dict[date]['temps'])
        temp_chart = temp_chart.render_data_uri()

        humid_style = LightenStyle('#6E9DF6', base_style=LightColorizedStyle)
        humid_chart = pygal.StackedLine(fill=True,
                                        interpolate='cubic',
                                        style=humid_style)
        humid_chart.title = 'Humidity as %'
        humid_chart.x_labels = map(str, weather_dict[date]['times'])
        humid_chart.add('Humidity', weather_dict[date]['humidity'])
        humid_chart = humid_chart.render_data_uri()

        wind_style = LightenStyle('#8A6DEC', base_style=LightColorizedStyle)
        wind_chart = pygal.StackedLine(fill=True,
                                       interpolate='cubic',
                                       style=wind_style)
        wind_chart.title = 'Windspeed in m/s'
        wind_chart.x_labels = map(str, weather_dict[date]['times'])
        wind_chart.add('Wind speeds', weather_dict[date]['windspeed'])
        wind_chart = wind_chart.render_data_uri()
        graph += [[temp_chart, humid_chart, wind_chart]]
    return graph
Beispiel #9
0
    def kcal_chart():
        """
            Calculates the average kcal of each cuisine group
        """

        # apply custom style to graph
        dark_blue_style = LightenStyle('#004466')

        # create chart type, labels, heading
        pie_chart = pygal.Pie(inner_radius=.4,
                              fill=True,
                              interpolate='cubic',
                              style=dark_blue_style,
                              tooltip_border_radius=10)
        pie_chart.title = 'Promig KCAL per Cuina'

        # nutrition is a 2d array and I had trouble with positional queries
        # For that reason two $project queries were used to unwind the 2d array
        cursor = db.recipes.aggregate([{
            "$project": {
                "_id": "$filters.cuina",
                "arr": {
                    "$arrayElemAt": ["$nutrition", 0]
                }
            }
        }, {
            "$project": {
                "_id": "$_id",
                "kcal": {
                    "$arrayElemAt": ["$arr", 1]
                }
            }
        }, {
            "$group": {
                "_id": "$_id",
                "avgKcal": {
                    "$avg": {
                        "$toInt": "$kcal"
                    }
                }
            }
        }])

        # add a new pie section to the graph for each group
        for item in cursor:
            if item['_id'] not in Graphs.unwanted_cuisines:
                pie_chart.add(item['_id'],
                              round(item['avgKcal'], 0),
                              formatter=lambda x: '%s kcals' % x)

        # render as data uri
        return pie_chart.render_data_uri()
def make_visualization(name, plot_dicts):
    """ Visualize most popular repositories with pygal bar chart. """
    my_style = LS('#336699', base_style=LCS)
    my_style.title_font_size = 24
    my_style.label_font_size = 14
    my_style.major_label_font_size = 18

    my_config = pygal.Config()
    my_config.value_formatter = lambda y: f'{y:,.0f}'  # format (123,456)
    my_config.x_label_rotation = 45
    my_config.show_legend = False
    my_config.tooltip_fancy_mode = False  # Hides title from tooltip on hover
    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 Projects on GitHub'
    chart.x_labels = names

    chart.add('', plot_dicts)
    chart.render_to_file('./working_with_apis/images/svg/python_repos.svg')
def make_visualization(names, plot_dict):
    """ Make a visualization of data with pygal bar chart. """
    my_style = LS('#733380', base_style=LCS)
    my_style.title_font_size = 24
    my_style.label_font_size = 14
    my_style.major_label_font_size = 18

    my_config = pygal.Config()
    my_config.value_formatter = lambda y: f'{y:,.0f}'  # format (123,456)
    my_config.x_label_rotation = 45
    my_config.show_legend = False
    my_config.tooltip_fancy_mode = 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 JavaScript Projects on GitHub'
    chart.x_labels = names

    chart.add('', plot_dicts)
    chart.render_to_file('./working_with_apis/images/svg/javascript_repos.svg')
def bar_plots(agency, year):
    category = list(date_retrieval_all(agency, year)[0].keys())
    height = list(date_retrieval_all(agency, year)[0].values())
    dark_lighten_style = LightenStyle('#004466',
                                      title_font_size=15,
                                      tooltip_font_size=12,
                                      label_font_size=10)
    line_chart = pygal.HorizontalBar(show_legend=False,
                                     style=dark_lighten_style,
                                     height=300,
                                     width=600)
    line_chart.title = 'Total Expenditure Per Procurement Category'
    for i in range(len(category)):
        line_chart.add(category[i], height[i])

    return (line_chart.render_to_file('Simple_Button/pygal/' + agency +
                                      'bar.svg'))
Beispiel #13
0
    if not solved_ext:
        solved_ext = 0
    else:
        solved_ext = int(solved_ext)
    if solved_ext == 0:
        solved = solved[:20]

    notSolved_ext = request.args.get('notSolved_ext')
    if not notSolved_ext:
        notSolved_ext = 0
    else:
        notSolved_ext = int(notSolved_ext)
    if notSolved_ext == 0:
        notSolved = notSolved[:20]

    customStyle = LightenStyle('#337ab7')
    customStyle.background = '#eeeeee'
    customStyle.label_font_size = 14
    customStyle.tooltip_font_size = 25

    chart_type = request.args.get('chart_type')
    if not chart_type:
        chart_type = 0
    else:
        chart_type = int(chart_type)

    chart = None
    if chart_type == 0:
        chart = pygal.Bar(show_legend=False, style=customStyle, order_min=0)
        chart.title = 'Problems solved per tag'
        chart.x_labels = allTags
Beispiel #14
0
core_samples_mask = np.zeros_like(model.labels_, dtype=bool)
core_samples_mask[model.core_sample_indices_] = True
labels = model.labels_
dataFrame['Cluster'] = model.labels_.tolist()

"""## Clusters of people within 6ft of each other specified in shades of red"""

disp_dict_clust = {}
for index, row in dataFrame.iterrows():
    if row['Cluster'] not in disp_dict_clust.keys():
        disp_dict_clust[row['Cluster']] = [(row['Latitude'], row['Longitude'])]
    else:
        disp_dict_clust[row['Cluster']].append((row['Latitude'], row['Longitude']))
print(len(disp_dict_clust.keys()))
from pygal.style import LightenStyle
dark_lighten_style = LightenStyle('#F35548')
xy_chart = pygal.XY(stroke=False, style=dark_lighten_style)
[xy_chart.add(str(k),v) for k,v in disp_dict_clust.items()]
display(HTML(base_html.format(rendered_chart=xy_chart.render(is_unicode=True))))

"""## Checking Potential Infected Persons

Users may assign the name of an infected person to the variable inputName to check who they came in contact with in a particular area and timeframe. Values is defaultly set to "Abdel Terne", but it may be changed to any of the 1000 people of the population, listed in the 1000people.csv file.
"""

inputName = "Abdel Terne"
inputNameClusters = set()
for i in range(len(dataFrame)):
    if dataFrame['User'][i] == inputName:
        inputNameClusters.add(dataFrame['Cluster'][i])
Beispiel #15
0
    url = ('https://hacker-news.firebaseio.com/v0/item/' + str(submission_id) +
           '.json')
    submission_r = requests.get(url)
    response_dict = submission_r.json()
    names.append(response_dict['title'])
    submission_dict = {
        'value': response_dict.get('descendants', 0),
        'xlink': 'http://news.ycombinator.com/item?id=' + str(submission_id),
    }
    submission_dicts.append(submission_dict)
    submission_dicts = sorted(submission_dicts,
                              key=itemgetter('value'),
                              reverse=True)

# Make visualization.
my_style = LS('#333366', base_style=LCS)
my_style.title_font_size = 16
my_style.major_label_font_size = 16

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 = 'Top 15 active discussions on Hacker News'
chart.x_labels = names[:15]

chart.add('', submission_dicts[:15])
Beispiel #16
0
print("Repositories returned: ", len(repos_dict), "\n")
names, plots = [], []
for item in repos_dict:
    names.append(item['name'])
    if item['description']:
        description = item['description']
    else:
        description = "No description provided."
    plots.append({
        'value': item['stargazers_count'],
        'label': description,
        'xlink': item['html_url'],
    })

# Make visualization
chart_style = LightenStyle('#333366', base_style=LightColorizedStyle)
chart_style.title_font_size = 18
chart_style.label_font_size = 12
chart_style.major_label_font_size = 14

chart_config = pygal.Config()
chart_config.x_label_rotation = 45
chart_config.show_legend = False
chart_config.truncate_label = 15
chart_config.show_y_guides = False
chart_config.width = 1000

chart = pygal.Bar(chart_config, style=chart_style)
chart.title = "Most-Starred Python Projects on GitHub"
chart.x_labels = names
chart.add("", plots)
Beispiel #17
0
names, plotDicts = [], []
for repoDict in repoDicts:
    names.append(repoDict['name'])

    description = repoDict['description']
    if not description:
        description = 'No description found.'

    plotDict = {
        'value': repoDict['stargazers_count'],
        'label': description,
        'xlink': repoDict['html_url'],
    }
    plotDicts.append(plotDict)

myStyle = LS('#666633', base_style=LCS)
myStyle.title_font_size = 24
myStyle.label_font_size = 14
myStyle.major_font_size = 18

myConfig = pygal.Config()
myConfig.x_label_rotation = 45
myConfig.show_legend = False
myConfig.truncate_lable = 15
myConfig.show_y_guides = False
myConfig.width = 1000

chart = pygal.Bar(myConfig, style=myStyle)
chart.title = 'Most starred python projects on Github'
chart.x_labels = names
Beispiel #18
0
# NOTE: pygal uses the value given for 'xlink' to turn each bar into an active
# link to the given url. You can also add links to the legend. See the docs:
# http://pygal.org/en/stable/documentation/configuration/value.html#legend

    plot_dict = {
        'value': repo_dict['stargazers_count'],
        'label': description,
        'xlink': repo_dict['html_url']
    }
    plot_dicts.append(plot_dict)

# Visualizing the repos with pygal
# -----------------------------------------------------------------------------

my_style = LS('#25bec4', base_style=LCS)
my_style.title_font_family = 'Helvetica'

# NOTE: google fonts will only render when the svg is embedded because the
# google stylesheet is added in the XML processing.
# my_style.title_font_family = 'googlefont:Slabo'

my_style.title_font_size = 14
my_style.foreground = '#586e75'
my_style.foreground_strong = '#334145'
my_style.foreground_subtle = '#fdca32'
my_style.label_font_size = 9
my_style.major_label_font_size = 12
my_style.tooltip_font_size = 11

my_config = pygal.Config()
Beispiel #19
0
repo_dicts = response_dict['items']
print("Repositories returned:", len(repo_dicts))

names, plot_dicts = [], []
for repo_dict in repo_dicts:
    names.append(repo_dict['name'])
    description = repo_dict['description']
    plot_dict = {
        'value': repo_dict['stargazers_count'],
        'label': description,
        'xlink': repo_dict['html_url']
    }
    plot_dicts.append(plot_dict)

# 将获取排行可视化
my_style = LS('#333366', base_style=LCS)
my_style.title_font_size = 22
my_style.label_font_size = 12
my_style.major_label_font_size = 18

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 ' + language.title() + ' Projects on GitHab'
chart.x_labels = names
chart.add('', plot_dicts)
Beispiel #20
0
description_plots, names, stars = [], [], []
for repo_dict in repo_dicts:
    names.append(repo_dict['name'])
    stars.append(repo_dict['stargazers_count'])

    description = repo_dict['description']
    if not description:  # we handle the issue of passing any empty value to the list
        description = "No Description provided"
    description_plot = {
        'value': repo_dict['stargazers_count'],
        'label': description,
        'xlink': repo_dict['html_url']
    }
    description_plots.append(description_plot)

my_style = LS('#333366', base_style=LCS)
my_style.label_font_size = 18
my_style.major_label_font_size = 18

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 = pygal.Bar(style=my_style, x_label_rotation=45, show_legend=True) after using my_config we changes it
# chart = pygal.HorizontalBar(style=my_style, x_label_rotation=45, show_legend=True)
chart.title = 'Most starred repositories'
chart.x_labels = names
"""

from csv import reader
import numpy as np
import pygal
from pygal.style import LightenStyle

import os

# set custom plot style
plot_style = LightenStyle('#0083b9',
                          step=5,
                          font_family='googlefont:Quantico',
                          font_size=22,
                          value_font_size=24,
                          value_label_font_size=22,
                          label_font_size=22,
                          major_label_font_size=22,
                          no_data_font_size=22,
                          title_font_size=22,
                          legend_font_size=15,
                          tooltip_font_size=18)


def read_data(filename):
    # read data file
    with open(filename, 'rt') as datafile:
        d = np.array(list(reader(datafile, delimiter=';')))

    # create dict where title is the key and a np array of floats represents the data columns
    data = {}
    for row in range(1, len(d)):
Beispiel #22
0
names, plot_dicts = [], []
for repo_dict in repo_dicts:
    names.append(repo_dict["name"])
    #stars.append(repo_dict["stargazers_count"])
    description = repo_dict["description"]
    if not description:
        description = "No description provided."
    plot_dict = {
        "value": repo_dict["stargazers_count"],
        "label": description,
        "xlink": repo_dict["html_url"]
    }

    plot_dicts.append(plot_dict)

my_style = LS("#333366", base_style=LCS)
my_style.title_font_size = 24
my_style.label_font_size = 14
my_style.major_label_font_size = 18

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 Projects on Guthub"
chart.x_labels = names

chart.add("", plot_dicts)
Beispiel #23
0
		bill_ratio = float(len(passed))/float(len(days_in_period))
	
		forecast = 0.0
		if bill_ratio > 0.0:
			forecast = this_mon.used / bill_ratio
	
		our_text = "At this rate we will take %.2f units into next month" % -(this_mon.bf+forecast-this_mon.allowance)
		over = False
		if this_mon.used > this_mon.allowance:
			our_text = "We are ALREADY using more data than we buy each month!"
			over = True
		elif forecast > this_mon.allowance:
			our_text = "We are forecast to use more data than we buy each month"
		
		from pygal.style import LightenStyle, LightColorizedStyle
		ourstyle = LightenStyle('#235670', step=5, base_style=LightColorizedStyle)
		ourstyle.background = '#ffffff'
		
		conf = pygal.Config()
		conf.style = ourstyle
		conf.legend_at_bottom = True
		
		usage_pie = pygal.Pie(conf)
		usage_pie.title = "Current monthly usage (units)"
		if over:
			usage_pie.add("Over-usage", this_mon.used - this_mon.allowance)
			usage_pie.add("Allowance", this_mon.allowance)
		else:
			usage_pie.add("Usage", this_mon.used)
			usage_pie.add("Remaining", this_mon.allowance - this_mon.bf)
		
Beispiel #24
0
import pygal
from pygal.style import LightColorizedStyle, LightenStyle

url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
response = requests.get(url)
response_dict = response.json()
repo_dicts = response_dict["items"]
names, star_plots = [], []
for repo in repo_dicts:
    names.append(repo['name'])
    star_plot = {
        'value': repo['stargazers_count'],
        'label': str(repo['description']),
        'xlink': repo['html_url'],
    }
    star_plots.append(star_plot)
my_style = LightenStyle('#333366', base_style=LightColorizedStyle)
my_config = pygal.Config()
my_config.x_label_rotation = 30
my_config.show_legend = False
my_config.title_font_size = 24
my_config.label_font_size = 14
my_config.major_label_font_size = 18
my_config.truncate_label = 15
my_config.show_y_guides = False
my_config.width = 1000
chart = pygal.Bar(config=my_config, style=my_style)
chart.title = "Most starred Python projects on Github"
chart.x_labels = names
chart.add('', star_plots)
chart.render_to_file('github_repo.svg')
project_name = []
plot_dicts_but_is_actually_a_list = []

for item in item_dict_but_is_actually_a_list:
    try:
        project_name.append(item['name'])
        information = {
            'value': item['stargazers_count'],
            'label': item['description'],
            'xlink': item['html_url']
        }
        plot_dicts_but_is_actually_a_list.append(information)
    except:
        pass

my_style = LightenStyle('#336676', step=5)

configuration = pygal.Config()
configuration.x_label_rotation = 45
configuration.title_font_size = 24
configuration.label_font_size = 12
configuration.truncate_label = 15
configuration.major_label_font_size = 14
configuration.width = 1000
configuration.show_y_guides = False
configuration.show_legend = False

bar_chart = pygal.HorizontalBar(configuration, style=my_style)
bar_chart.title = 'Most Starred Java Projects on GitHub'
bar_chart.x_labels = project_name
bar_chart.add('', plot_dicts_but_is_actually_a_list)
Beispiel #26
0
def make_graph():
    """make graph in section center"""

    #open worksheet
    book = open_workbook('D:/PSIIT/job58.xlsx')
    sheet = book.sheet_by_index(0) #select sheet
    law = [sheet.cell(1, col_index).value for col_index in range(1, 13)]
    profess = [sheet.cell(2, col_index).value for col_index in range(1, 13)]
    tech = [sheet.cell(3, col_index).value for col_index in range(1, 13)]
    clerk = [sheet.cell(4, col_index).value for col_index in range(1, 13)]
    market = [sheet.cell(5, col_index).value for col_index in range(1, 13)]
    fishing = [sheet.cell(6, col_index).value for col_index in range(1, 13)]
    business = [sheet.cell(7, col_index).value for col_index in range(1, 13)]
    fact = [sheet.cell(8, col_index).value for col_index in range(1, 13)]
    sale = [sheet.cell(9, col_index).value for col_index in range(1, 13)]
    other = [sheet.cell(10, col_index).value for col_index in range(1, 13)]

    #make graph
    neon_lighten_style = LightenStyle('#004466', base_style=DarkStyle)
    line_chart = pygal.Bar(x_label_rotation=25, style=neon_lighten_style) #style's graph
    line_chart.title = 'ภาวะการทำงานของประชากร พ.ศ. 2558'
    career = []
    count_law = 0
    count_profess = 0
    count_tech = 0
    count_clerk = 0
    count_market = 0
    count_fishing = 0
    count_business = 0
    count_fact = 0
    count_sale = 0
    count_other = 0
    #แกนx
    for i in [sheet.cell(col_index, 0).value for col_index in range(1, 11)]:
        career.append(i)
    #ave per month
    for i in law:
        count_law += i
    count_law = float("%.2f" %(count_law/12))
    for i in profess:
        count_profess += i
    count_profess = float("%.2f" %(count_profess/12))
    for i in tech:
        count_tech += i
    count_tech = float("%.2f" %(count_tech/12))
    for i in clerk:
        count_clerk += i
    count_clerk = float("%.2f" %(count_clerk/12))
    for i in market:
        count_market += i
    count_market = float("%.2f" %(count_market/12))
    for i in fishing:
        count_fishing += i
    count_fishing = float("%.2f" %(count_fishing/12))
    for i in business:
        count_business += i
    count_business = float("%.2f" %(count_business/12))
    for i in fact:
        count_fact += i
    count_fact = float("%.2f" %(count_fact/12))
    for i in sale:
        count_sale += i
    count_sale = float("%.2f" %(count_sale/12))
    for i in other:
        count_other += i
    count_other = float("%.2f" %(count_other/12))

    
    line_chart.x_labels = map(str, career)
    line_chart.add('Average/year', [count_law, count_profess, count_tech, count_clerk, count_market,\
                           count_fishing, count_business, count_fact, count_sale, count_other])
    line_chart.render_to_file('ave58.svg')
def drawRadar_pygal(title, case_data, path, showPlot):
    title = title[0:1] + title[-1:0:-1]
    case_data = case_data[0:1] + case_data[-1:0:-1]

    dark_lighten_style = LightenStyle(theme_color, step=5, max_=10)
    dark_lighten_style1 = LightenStyle('#ff0000')
    colorset = ['#cfefdf', '#a7e1c4', '#76d0a3']

    dark_lighten_style.opacity = 0.5
    dark_lighten_style.background = '#ffffff'
    dark_lighten_style.font_family = "DejaVu Sans"
    dark_lighten_style.legend_font_family = "DejaVu Sans"
    dark_lighten_style.major_label_font_family = "DejaVu Sans"
    dark_lighten_style.title_font_family = "DejaVu Sans"
    dark_lighten_style.tooltip_font_family = "DejaVu Sans"
    dark_lighten_style.label_font_family = "DejaVu Sans"
    dark_lighten_style.label_font_size = 40
    dark_lighten_style.major_label_font_size = 40
    dark_lighten_style.legend_font_size = 40
    dark_lighten_style.colors = [colorset[1], theme_color]
    #     dark_lighten_style.foreground = 'rgba(0, 0, 0, .87)'
    #     raise

    radar_chart = pygal.Radar(show_legend=True,
                              width=1600,
                              height=1200,
                              style=dark_lighten_style,
                              margin=25,
                              spacing=20,
                              stroke_style={'width': 5},
                              dots_size=8,
                              show_dots=1,
                              stroke=1)
    # radar_chart.title = 'V8 benchmark results'
    radar_chart.x_labels = title
    if max(case_data) < 1:
        case_data = [c * 100 for c in case_data]
#     radar_chart.add('Chrome1', [{'value':50,'style': 'fill: False; stroke: red; stroke-width: 4;stroke-dasharray: 15, 10, 5, 10, 15'}]*len(case_data))
    radar_chart.add('Standard score', [50] * len(case_data),
                    fill=True,
                    show_dots=0,
                    stroke_style={
                        'width': 2,
                        'dasharray': '3, 6'
                    })

    radar_chart.add('Your score', case_data)
    #     radar_chart._fill('red')
    radar_chart.y_labels = [0, 50, 100]

    #     radar_chart.render_to_file('plot/Radar_pygal.svg',fill = True)
    radar_chart.render_to_png(path + 'Radar_pygal.png', fill=True)
    if showPlot:
        display({'image/svg+xml': radar_chart.render(fill=True)}, raw=True)
Beispiel #28
0
import pygal
from pygal.style import LightenStyle, LightColorizedStyle

chart_style = LightenStyle('#3399AA', base_style=LightColorizedStyle)
chart_config = pygal.Config()
chart_config.width = 500  #默认800
chart_config.x_label_rotation = 45
chart_config.show_legend = False  #隐藏图例

chart = pygal.Bar(chart_config, style=chart_style)
chart.title = 'Python Projects'
chart.x_labels = ['httpie', 'django', 'flask']

#2.2 添加自定义工具提示 ---- 字典:'value':数据进行绘制直线图,'label':描述数据的描述
plot_dicts = [{
    'value': 10000,
    'label': 'Description of httpie'
}, {
    'value': 20000,
    'label': 'Description of django'
}, {
    'value': 30000,
    'label': 'Description of flask'
}]
chart.add('', plot_dicts)
chart.render_to_file('bar_descriptions.svg')
def drawPercentile(percentile, x_label, path, showPlot):

    config = Config()
    config.show_legend = False
    # config.range = (0,1)

    dark_lighten_style = LightenStyle('#336676',
                                      base_style=LightColorizedStyle)
    dark_lighten_style.background = '#ffffff'
    dark_lighten_style.opacity = 1
    dark_lighten_style.font_family = "DejaVu Sans"
    dark_lighten_style.legend_font_family = "DejaVu Sans"
    dark_lighten_style.major_label_font_family = "DejaVu Sans"
    dark_lighten_style.title_font_family = "DejaVu Sans"
    dark_lighten_style.tooltip_font_family = "DejaVu Sans"
    dark_lighten_style.label_font_family = "DejaVu Sans"
    dark_lighten_style.label_font_size = 40
    dark_lighten_style.major_label_font_size = 40

    #     print(dark_lighten_style.to_dict())

    bar_chart = pygal.Bar(config,
                          width=1600,
                          height=1000,
                          rounded_bars=6,
                          style=dark_lighten_style,
                          margin=0)

    bar_chart.x_labels = x_label  #['Concentration', 'Stability', 'Focus Continuity'] #map(str, range(2002, 2013))
    bar_chart.y_labels = (0, 0.2, 0.4, 0.6, 0.8, 1)

    # bar_chart.add('Percentile0', rd1.percentile[0])
    # bar_chart.add('Percentile1', rd1.percentile[1])
    # bar_chart.add('Percentile2', rd1.percentile[2])

    bar_chart.add('Percentile', [{
        'value': 1 - percentile[0],
        'color': selectColor(percentile[0])
    }, {
        'value': 1 - percentile[1],
        'color': selectColor(percentile[1])
    }, {
        'value': 1 - percentile[2],
        'color': selectColor(percentile[2])
    }])
    if showPlot:
        display({'image/svg+xml': bar_chart.render()}, raw=True, dpi=200)

    bar_chart.render_to_png(path + 'Percentile.png', fill=True, dpi=200)
        'label': describe,
        'xlink': repo_dict['html_url']
    }
    plot_dicts.append(plot_dict)
'''
    print('\nName:', repo_dict['name'])
    print('Owner:', repo_dict['owner']['login'])
    print('Stars:', repo_dict['stargazers_count'])
    print('Repository:', repo_dict['html_url'])
    print('Created:', repo_dict['created_at'])
    print('Updated:', repo_dict['updated_at'])
    print('Description:', repo_dict['description'])
'''

##Make visualization.
p_style = LS('#333366', basestyle=LCS)

p_style.title_font_size = 24
p_style.label_font_size = 12
p_style.major_label_font_size = 14

p_config = pygal.Config()
p_config.x_label_rotation = 45
p_config.show_legend = False
p_config.truncate_label = 15
#p_config.show_y_guides = False
p_config.width = 1000

chart = pygal.Bar(p_config, style=p_style)
chart.title = 'Most-Starred C Project on GitHub'
chart.x_labels = names
Beispiel #31
0
from pygal_maps_ru.maps import REGIONS, REGIONS_EN, Regions, Regions_en, DISTRICTS, District, DISTRICTS_EN, District_en
from pygal.style import LightenStyle
import random

data_region = {}
data_region_en = {}
data_district = {}
data_district_en = {}

style1 = LightenStyle('#336676')
style2 = LightenStyle('#886622')
style3 = LightenStyle('#116699')
style4 = LightenStyle('#551144')

for code, name in REGIONS.items():
    data_region[code] = random.randrange(1000000)

for code, name in REGIONS_EN.items():
    data_region_en[code] = random.randrange(1000000)

for code, name in DISTRICTS.items():
    data_district[code] = random.randrange(1000000)

for code, name in DISTRICTS_EN.items():
    data_district_en[code] = random.randrange(1000000)

wm_region = Regions(style=style1)
wm_region_en = Regions_en(style1=style2)
wm_district = District(style=style3)
wm_district_en = District_en(style=style4)
Beispiel #32
0
    names.append(repo_dict['name'])

    #Get the project description if one is available
    description = repo_dict['description']
    if not description:
        description = 'NO Description provided.'

    plot_dict = {
        'value': repo_dict['stargazers_count'],
        'label': description,
        'xlink': repo_dict['html_url'],
    }
    plot_dicts.append(plot_dict)

# Make Visualization.
my_style = LS('#333366', base_style=LCS)
my_style.title_font_size = 24
my_style.laber_font_size = 14
my_style.major_label_font_size = 18

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 projects on GitHub'
chart.x_labels = names
Beispiel #33
0
from bugs.models import Bug
from features.models import Feature

import pygal
from pygal.style import Style, LightenStyle, DefaultStyle

dark_lighten_style = LightenStyle('#A9A9A9',
              background='transparent',
              opacity='.6',
              opacity_hover='.9',
              transition='400ms ease-in',
              title_font_size = 40,
              tooltip_font_size = 26,
              font_family = 'Muli',
              legend_font_size	 = 18,
                                   )


def bug_pie_chart():
    """
    This function creates a pie chart for use on the profile page
    it gives our users some statistics on our bug model
    """
    todo = Bug.objects.filter(status="To do").count()
    progress = Bug.objects.filter(status="In progress").count()
    complete = Bug.objects.filter(status="Complete").count()
    
    pie_chart = pygal.Pie(
        print_values=False,
        human_readable=True,
        show_legend=True,