Ejemplo n.º 1
0
def graph():
    global temp_list, OD_list, pH_list, timestamp_list, setpoint_T, setpoint_OD
    graph1 = pygal.StackedLine(show_y_guides=False, x_title='Time', y_title='Temperature', x_label_rotation=20, fill=True, interpolate='cubic')
    graph1.title = "Temp vs Time"
    graph1.x_labels = timestamp_list
    graph1.add('Temp', temp_list)
    graph1.add('Setpoint', setTemp)
    
    graph2 = pygal.StackedLine(show_y_guides=False, x_title='Time', y_title='Optical Density', x_label_rotation=20, fill=True, zero=setpoint_T, interpolate='cubic', style = DarkStyle)
    graph2.title = "OD vs Time"
    graph2.x_labels = timestamp_list
    graph2.add('OD', OD_list)
    graph2.add('Setpoint', setOD)

    
    graph3 = pygal.StackedLine(show_y_guides=False, x_title='Time', y_title='pH', x_label_rotation=20, fill=True, zero=setpoint_OD, interpolate='cubic', style = NeonStyle)
    graph3.title = "pH vs Time"
    graph3.x_labels = timestamp_list
    graph3.add('pH', pH_list)
    
    graph1=graph1.render_data_uri()
    graph2=graph2.render_data_uri()
    graph3=graph3.render_data_uri()

    
    return render_template('graph.html', graph1=graph1, graph2=graph2, graph3=graph3)
Ejemplo n.º 2
0
def index():
    """Creates the graphics with the last five data stored in the database 
    for each variable measured.
    
    """

    # Create the graphs from pygal library:
    graph_t = pygal.StackedLine(fill=True)
    graph_l = pygal.StackedLine(fill=True)
    graph_h = pygal.StackedLine(fill=True)

    # Titles:
    graph_t.title = 'Temperature values'
    graph_l.title = 'Luminosity values'
    graph_h.title = 'Humidity values'

    # Labels for the X labels:
    graph_t.x_labels = ['1', '2', '3', '4', '5']
    graph_l.x_labels = ['1', '2', '3', '4', '5']
    graph_h.x_labels = ['1', '2', '3', '4', '5']

    # Gets the information from the Database
    data_temp_base = Temperatures.query.all()
    data_lum_base = Luminosities.query.all()
    data_hum_base = Humidities.query.all()

    data_temp = []
    data_lum = []
    data_hum = []

    for d1 in data_temp_base:
        data_temp.append(d1.data)

    for d2 in data_lum_base:
        data_lum.append(d2.data)

    for d3 in data_hum_base:
        data_hum.append(d3.data)

    graph_t.add('Temp', data_temp[-5:])
    graph_l.add('Lum', data_lum[-5:])
    graph_h.add('Hum', data_hum[-5:])

    graph_data_t = graph_t.render_data_uri()
    graph_data_l = graph_l.render_data_uri()
    graph_data_h = graph_h.render_data_uri()

    return flask.render_template('index.html',
                                 graph_data_t=graph_data_t,
                                 graph_data_l=graph_data_l,
                                 graph_data_h=graph_data_h,
                                 title='WSN Practical Work')
Ejemplo n.º 3
0
    def draw2(self):
        custom_css_file = '/tmp/pygal_custom_style.css'
        self.config = pygal.Config(fill=True)
        self.config.css.append('file://' + custom_css_file)
        self.chart = pygal.StackedLine(self.config,
                                       fill=True,
                                       style=self.style,
                                       dots_size=0,
                                       legend_at_bottom=True,
                                       legend_at_bottom_columns=3)
        self.chart.title = self.title
        self.chart.x_title = "Tahun Event"
        self.chart.y_title = "Jumlah Medali"

        # draw using the json data
        years, golds, silvers, bronzes, ranks = [], [], [], [], []
        for yearly_medal in self.shown_data:
            years.append(int(yearly_medal['Tahun']))
            medals = yearly_medal['Data']
            golds.append(int(medals['Emas']))
            silvers.append(int(medals['Perak']))
            bronzes.append(int(medals['Perunggu']))
            ranks.append(int(medals['Peringkat']))

        self.chart.x_labels = years
        self.chart.add('Emas', golds)
        self.chart.add('Perak', silvers)
        self.chart.add('Perunggu', bronzes)
Ejemplo n.º 4
0
def pygalexample():
    graph = pygal.StackedLine(fill=True,
                              interpolate='cubic',
                              style=DarkColorizedStyle)
    graph.title = 'A web scraped weather data showing the current weather in our beloved city of Braislava.'
    graph.x_labels = ['Day0', 'Day1', 'Day2', 'Day3', 'Day4']
    graph.add('Minimum Temp', [
        day_1_5_min_temp[0], day_1_5_min_temp[1], day_1_5_min_temp[2],
        day_1_5_min_temp[3], day_1_5_min_temp[4]
    ])
    graph.add('Maximum Temp', [
        day_1_5_max_temp[0], day_1_5_max_temp[1], day_1_5_max_temp[2],
        day_1_5_max_temp[3], day_1_5_max_temp[4]
    ])
    graph.add('average_temp', [
        day_1_5_avg_temp[0], day_1_5_avg_temp[1], day_1_5_avg_temp[2],
        day_1_5_avg_temp[3], day_1_5_avg_temp[4]
    ])
    graph.add('Humidity', [
        day_1_5_humidity[0], day_1_5_humidity[1], day_1_5_humidity[2],
        day_1_5_humidity[3], day_1_5_humidity[4]
    ])

    graph_data = graph.render_data_uri()
    return render_template("index.html", graph_data=graph_data)
Ejemplo n.º 5
0
def team_points_stacked_line_graph(team_name, breakdown_df):
    """Returns a stacked line graph giving the cumulative weekly breakdown of points for a specific team
    
    :param team_name The team name to generate the graph of
    :param breakdown_df The dataframe containing the data needed (in this case we will have breakdown_df = team_players_breakdown_df(team_name, team_list_df)"""

    # Get cumulative data
    zeros = []
    data = []
    for _, row in breakdown_df.iterrows():
        label = f"{row['Name']}"
        values = row[weeks]
        zeros.append(count_trailing_zeros(values))
        values = cumulative(values)
        data.append((label, values))

    # Number of weeks to trim
    min_zeros = min(zeros)

    # Generate graph
    graph = pygal.StackedLine(style=style, fill=True)
    graph.title = f"{team_name} Points Tracker"
    graph.x_labels = weeks[:-min_zeros]
    for label, values in data:
        graph.add(label, values[:-min_zeros], allow_interruptions=True)

    # Render graph
    graph_data = graph.render_data_uri()
    return graph_data
Ejemplo n.º 6
0
def gold():
    """
        READ csv.file [Date, Price]
        Create List 'lstdate', 'lstprice'
    """
    data = pd.read_csv('annual_csv.csv')
    lstdate = []  #--------->list for append.years<---------------
    lstprice = []  #--------->List for append Gold Price<----------
    #Create Data List
    #------------------->run data in annual_csv.csv<-----------------------
    for i in data.Date:
        lstdate.append(str(i))
    #print(lstdate)

    for j in data.Price:
        lstprice.append(float(j))
    #print(lstprice)


#Plot Graph with Pygal
#---------------------------------->Custom Graph<--------------------------------------
    chart = pygal.StackedLine(fill=True, show_x_labels=True, plot_background='F9BF17', y_title='ราคา(USD)',\
     x_title='ปี ค.ศ. 1950 จนถึงปัจจุบัน', x_labels=lstdate, tooltip_border_radius=3, style=custom_style, \
     title = 'ราคาทองหน่วยดอลลาร์สหรัฐตั้งเเต่ ค.ศ.1950 จนถึงปัจจุบัน', range=[1, 2000])   #Grpah Title

    #----------------------------------->Data in Graph<------------------------------------
    chart.add('ราคาทองในปี', lstprice, show_dots=True,
              dots_size=2)  #Gold Price graph
    #chart.add('Years', lstdate)

    chart.render_to_file('graphh.svg')  #Render Graph for use
Ejemplo n.º 7
0
def main():
    """ Main function """
    data_game = pandas.read_csv("vgsales.csv")
    data_year = numpy.array(
        data_game.groupby(["Genre", "Year"],
                          as_index=False).count()[["Genre", "Year",
                                                   "Rank"]]).tolist()
    data_genre = [
        i
        for i in (data_game.groupby(["Genre"], as_index=False).count()["Genre"]
                  ).tolist()
    ]

    chart = pygal.StackedLine(fill=True, interpolate='cubic', dots_size=1.75)
    chart.x_labels = range(1980, 2017)
    chart.x_labels_major_count = 8
    chart.show_minor_x_labels = False
    chart.y_labels = [i for i in range(0, 1601, 200)]
    chart.y_labels_major_every = 5
    chart.truncate_label = 5
    chart.legend_at_bottom = True
    chart.legend_box_size = 16
    chart.x_title = "Year"
    chart.y_title = "Video Games Amount"

    for i in data_genre:
        temp = project.fill_missing_year([[int(float(j[1])), j[2]]
                                          for j in data_year if j[0] == i])
        chart.add(i, [j[1] for j in temp])

    chart.render_to_file("releases_genre.svg")
Ejemplo n.º 8
0
def render_historical_chart(data):
    chart = pygal.StackedLine(fill=True)
    chart.x_labels = data['X-LABELS']
    del data['X-LABELS']
    for name, entry_data in data.items():
        chart.add(name, entry_data[reports.Y_POS])
    return chart.render(disable_xml_declaration=True)
Ejemplo n.º 9
0
def monthly(request):
    if not request.user.is_authenticated:
        return redirect("/login/")

    if request.method == "POST":
        p_money = int(request.POST.get('pocket_money'))
        daily_expense = int(request.POST.get('daily_expense'))

        xaxis = []
        dataset = []

        for i in range(1, 31, 1):
            xaxis.append(str(i))
            moneyleft = p_money - (daily_expense * i)
            dataset.append(moneyleft)
            if moneyleft < 0:
                break

        days = float((p_money) / (daily_expense))
        line_chart = pygal.StackedLine(fill=True, interpolate='cubic')
        line_chart.title = 'pocket money'
        line_chart.x_labels = xaxis
        line_chart.add('', dataset)
        chart = line_chart.render_data_uri()

        return render(request, "billapp/monthly.html", {
            'days': days,
            'chart': chart
        })

    return render(request, "billapp/monthly.html")
Ejemplo n.º 10
0
def create_graph(all_data):
    tree_colors = ('#00aa00', '#22aa00', '#44aa00', '#66aa00', '#88aa00',
                   '#aaaa00', '#aa8800', '#aa6600', '#aa4400', '#aa2200',
                   '#aa0000')

    TreeStyle = pygal.style.Style(background='#ffffaa',
                                  plot_background='#dddddd',
                                  foreground='#000000',
                                  foreground_light='#000000',
                                  foreground_dark='#000000',
                                  opacity='.75',
                                  opacity_hover='.9',
                                  transition='200ms ease-in',
                                  colors=tree_colors)

    data = convert_data(all_data)
    line_chart = pygal.StackedLine(fill=True,
                                   style=TreeStyle,
                                   x_label_rotation=20,
                                   interpolate='hermite')  #'lagrange'
    line_chart.title = 'How High Is R/Trees?'
    dates = get_dates(all_data)
    line_chart.x_labels = dates  #map(str, range(0,len(all_data)))
    for i, d in enumerate(data):
        line_chart.add(str(i), d)
    line_chart.render_to_file('chart.svg')
    return
Ejemplo n.º 11
0
def get_weather_data():

    # create a bar chart
    title = 'entities'
    # bar_chart = pygal.Bar(width=1200, height=600,
    #                       explicit_size=True, title=title, style=DarkSolarizedStyle)
    bar_chart = pygal.StackedLine(width=1200,
                                  height=600,
                                  explicit_size=True,
                                  title=title,
                                  fill=True)

    bar_chart.x_labels = ['apple', 'oranges', 'grapes']
    imp_temps = [20, 59, 1]
    bar_chart.add('Temps in F', imp_temps)

    html = """
        <html>
             <head>
                  <title>%s</title>
             </head>
              <body>
                 %s
             </body>
        </html>
        """ % (title, bar_chart.render())
    return html
Ejemplo n.º 12
0
def alerts_by_reason_in_24h(date, chart_data):
    """
    Generate charts about alert counts by reasons and hours in a day
    :param date, chart_data:
    :return: Create new svg and png chart file in current dir.
    """
    line_chart = pygal.StackedLine(fill=True,
                                   truncate_legend=-1,
                                   human_readable=True)
    line_chart.title = 'Alerts in 24 hours of ' + date
    line_chart.x_labels = map(str, range(0, 24))
    dict_24hours = {c: [0] * 24 for c in range(1, 16)}
    for alert_time_reason in chart_data:
        alert_dt = datetime.datetime.strptime(alert_time_reason[0],
                                              "%Y-%m-%dT%H:%M:%S%z")
        if int(alert_dt.strftime('%Y%m%d')) == int(date):
            reason_code = alert_time_reason[1]
            hour = int(alert_dt.strftime('%H'))
            dict_24hours[reason_code][hour - 1] += 1
    for k in dict_24hours.keys():
        if sum(dict_24hours[k]) == 0:
            continue
        line_chart.add(reason_dict_en[k], dict_24hours[k], show_dots=False)
    line_chart.human_readable = True
    line_chart.force_uri_protocol = 'http'
    line_chart.render_to_file('%s24h_stackedline_chart_%s.svg' %
                              (PIC_DIR, date))
    line_chart.render_to_png('%s24h_stackedline_chart_%s.png' %
                             (PIC_DIR, date))
Ejemplo n.º 13
0
    def plot_pop(self):
        pop_size, original_genes, genes = self.get_population_data()
        x = range(len(pop_size))
        chart1 = pygal.XY(style=DarkStyle,
                          legend_at_bottom=True,
                          show_dots=False,
                          fill=True)
        chart1.title = str(
            'Genome diversity in population with asexual reproduction over ' +
            str(len(pop_size)) +
            ' generations. \n Quantity of original genes from the first generation in population '
        )
        chart1.add('Population size', list(zip(x, pop_size)))
        chart1.add('Diversity', list(zip(x, original_genes)))
        chart1.render_to_file('charts/Autogamy_1.svg')

        genes = np.array(genes).T

        x2 = map(str, range(len(genes)))
        chart2 = pygal.StackedLine(fill=True,
                                   show_dots=False,
                                   style=DarkStyle,
                                   legend_at_bottom=True,
                                   truncate_label=-1)
        chart2.title = 'Genome diversity in population with asexual reproduction \n over ' + str(
            len(pop_size)) + ' generations'
        chart2.x_labels = self.get_x_lables(pop_size)

        for x2_, genes_ in zip(x2, genes):
            chart2.add('"' + str(x2_) + '"', genes_)
        chart2.render_to_file('charts/Autogamy_2.svg')
Ejemplo n.º 14
0
def player_points_line_graph(player_name, player_points_df):
    """Returns a stacked line graph giving the cumulative weekly points of a given player broken down by their role

    :param player_name The player to generate the graph of
    :param player_points_df The dataframe containing the necessary data (in this case we will obtain in from the player_points_df() function"""

    # Get cumulative data
    zeros = []
    data = []
    roles = player_points_df.columns
    for role in roles:
        values = player_points_df[role]
        zeros.append(count_trailing_zeros(values))
        values = cumulative(values)
        data.append((role, values))

    # Number of weeks to trim
    min_zeros = min(zeros)

    # Generate graph
    graph = pygal.StackedLine(style=style, fill=True)
    graph.title = f"{player_name} Points Tracker"
    graph.x_labels = weeks[:-min_zeros]
    for label, values in data:
        graph.add(label, values[:-min_zeros], allow_interruptions=True)

    # Render graph
    graph_data = graph.render_data_uri()
    return graph_data
Ejemplo n.º 15
0
def create_chart(ac, ad, fi, mi, pl, pu, ra, ro, sh, si, sp, st):
    """ This Function for create chart """
    chart = pygal.StackedLine(dots_size=1.75, legend_at_bottom=True, interpolate='cubic', fill=True)

    chart.x_title = 'Year'
    chart.y_title = 'Sales (in millions)'

    chart.x_labels = [i for i in range(1980, 2017)]
    chart.x_labels_major_count = 8
    chart.show_minor_x_labels = False
    chart.y_labels = [i for i in range(0, 701, 100)]
    chart.truncate_label = 5
    chart.legend_box_size = 16

    chart.add("Action", [i[1] for i in ac])
    chart.add("Adventure", [i[1] for i in ad])
    chart.add("Fighting", [i[1] for i in fi])
    chart.add("Misc", [i[1] for i in mi])
    chart.add("Platform", [i[1] for i in pl])
    chart.add("Puzzle", [i[1] for i in pu])
    chart.add("Racing", [i[1] for i in ra])
    chart.add("Role-Playing", [i[1] for i in ro])
    chart.add("Shooter", [i[1] for i in sh])
    chart.add("Simulation", [i[1] for i in si])
    chart.add("Sports", [i[1] for i in sp])
    chart.add("Strategy", [i[1] for i in st])

    chart.render_to_file('sales_genre.svg')
def data_prot(filename):
    """prot chart from input csv file"""
    with open(mydir + filename) as fp:
        reader = csv.DictReader(fp)
        num = [i for i in (reader.fieldnames)]

        chart_1 = pygal.StackedLine(fill=True,
                                    interpolate='cubic',
                                    style=chart_style1,
                                    show_legend=False)
        chart_1.value_formatter = lambda x: "%gM" % (x / (10**6))
        chart_1.x_labels = num
        data = next(reader)
        chart_1.add(None, [int(data[i]) if data[i] != 'None' else None for i in num], \
            allow_interruptions=True,  formatter=lambda y: "{:,.0f}(kWh)".format(y))
        chart_1.render_to_file(out_path + filename[:-4] + '_chart_1.svg')
        chart_2 = pygal.Bar(legend_at_bottom=True)
        chart_2.value_formatter = lambda x: "%gM" % (x / (10**6))
        chart_2.x_labels = num
        for i in range(5):
            data = next(reader)
            chart_2.add(name_y[i], [int(data[i]) if data[i] != 'None' else None for i in num], \
                allow_interruptions=True,  formatter=lambda y: "{:,.0f}(kWh)".format(y))
        chart_2.render_to_file(out_path + filename[:-4] + '_chart_2.svg')
        print("\tSuccess!")
Ejemplo n.º 17
0
def generate_country_sparkline(data):
    """ Generates a sparkline that shows the development of bridge-usage over
        a period of time.
    """
    chart = pygal.StackedLine(fill=True, show_x_labels=False, include_x_axis=True,
                              show_y_labels=False, margin=0, style=TorcollectStyle())
    chart.add('', data)
    return clean_graph(chart.render_sparkline(interpolate="cubic"))
Ejemplo n.º 18
0
Archivo: grapher.py Proyecto: cmry/gomi
 def __graph(self, p):
     if self.args['--style'] == 'bar':
         return pygal.Bar(logarithmic=True if 'log' in p else
                          False)  # , style=pygal.style.LightColorizedStyle)
     if self.args['--style'] == 'line':
         return pygal.StackedLine(logarithmic=True if 'log' in p else False,
                                  x_label_rotation=30)
     else:
         exit("Ye focked it.")
def get_graph_2():
    line_chart = pygal.StackedLine(fill=True, interpolate='cubic', style=CleanStyle)
    line_chart.title = 'Memory usage evolution (in %)'
    line_chart.x_labels = map(str, range(0, 100))
    line_chart.y_labels = map(str, range(100, 200))
    line_chart.add('Memory', [5, 25, 73, 2, 5, 7, 17, 100, 33, 75, 16, 13, 37, 7])
    line_chart.render()
    graph_data = line_chart.render_data_uri()
    return graph_data
Ejemplo n.º 20
0
def pygal_line_stacked(data, chartname, file_name):
    line_chart = pygal.StackedLine(print_values=True)
    line_chart.title = chartname
    for ds in data:
        for key, value in ds.items():
            line_chart.add(key, value)
    line_chart.render_to_file(file_name + '.svg')
    line_chart.render_to_png(file_name + '.png')
    return True
Ejemplo n.º 21
0
def stacked_line_chart():
    line = pygal.StackedLine(fill=True)
    line.title = 'STACKED LINE CHART TEST'
    line.x_labels = map(str, range(size))
    data = get_increment_data(size)
    other = [100 - x for x in data]
    line.add('main', data)
    line.add('other', other)
    line.render_to_file(get_file_name(inspect.stack()[0][3]))
def get_graph_4():
    line_chart = pygal.StackedLine(fill=True, interpolate='cubic', style=DarkColorizedStyle)
    line_chart.title = 'Networks usage evolution (in %)'
    line_chart.x_labels = map(str, range(2002, 2012))
    # line_chart.y_labels = map(str, range(0, 100))
    line_chart.add('Networks', [2, 3, 5, 9, 12, 9, 5, 1, 3, 5, 16, 13, 3, 7])
    line_chart.render()
    graph_data = line_chart.render_data_uri()
    return graph_data
def get_graph_3():
    line_chart = pygal.StackedLine(fill=True, interpolate='cubic', style=NeonStyle)
    line_chart.title = 'Hard Disk usage evolution (in %)'
    line_chart.x_labels = map(str, range(0, 100))
    # line_chart.y_labels = map(str, range(0, 100))
    line_chart.add('Hard Disk', [6, 10, 9, 7, 3, 1, 0, 1, 3, 5, 16, 13, 3, 7])
    line_chart.render()
    graph_data = line_chart.render_data_uri()
    return graph_data
Ejemplo n.º 24
0
def plot_baseline_percentage(plot_name):
	User = Query()
	dataset_data=db.search(User.dataset_name.matches(dataset_name))
	line_chart = pygal.StackedLine(fill=True)
	line_chart.title = "Flagged Baseline data percentage on {0}".format(dataset_name)
	line_chart.x_labels = map(str, dataset_data[0]['baseline_flag_perc'].keys())
	for data in dataset_data:
		line_chart.add(data['stage'], data['baseline_flag_perc'].values())		
	line_chart.render_to_file(plot_name)
def get_graph_1():
    line_chart = pygal.StackedLine(fill=True, interpolate='cubic', style=DefaultStyle)
    line_chart.title = 'CPU usage evolution (in %)'
    line_chart.x_labels = map(str, range(2002, 2012))
    # line_chart.y_labels = map(str, range(200, 400))
    line_chart.add('CPU', [1, 3, 5, 16, 13, 3, 7, 1, 3, 5, 16, 13, 3, 7])
    line_chart.render()
    graph_data = line_chart.render_data_uri()
    return graph_data
Ejemplo n.º 26
0
def rvm_make_stacked_chart():
    rvm_comp_stacked = pygal.StackedLine(fill=True, interpolate='cubic', style=NeonStyle)
    rvm_comp_stacked.title = "Messi vs Ronaldo Goals/Appearances"
    rvm_comp_stacked.x_labels = map(str, range(2002, 2015))
    rvm_comp_stacked.add(RonaldoGoalsName, RonaldoGoalsData)
    rvm_comp_stacked.add(RonaldoAppearancesName, RonaldoAppearancesData)
    rvm_comp_stacked.add(MessiGoalsName, MessiGoalsData)
    rvm_comp_stacked.add(MessiAppearancesName, MessiAppearancesData)
    rvm_comp_stacked.render_to_file("Ronaldo vs Messi Comparison2.html")
Ejemplo n.º 27
0
def graph3():
    dataframe = pd.read_sql_query(
        "SELECT emp_details.IDno,emp_details.Fname,emp_details.DoB,emp_salary.Amount,emp_salary.pay_date FROM emp_details INNER JOIN emp_salary ON emp_details.IDno=emp_salary.IDno",
        conn)
    print(dataframe)
    line_chart = py.StackedLine(fill=True)
    line_chart.title = 'Browser usage evolution (in %)'
    line_chart.x_labels = dataframe['DoB'].tolist()
    line_chart.add('SALARY', dataframe['Amount'].tolist())
    return Response(response=line_chart.render(), content_type='image/svg+xml')
Ejemplo n.º 28
0
def index():
    global times_data, temp_data
    line_chart = pygal.StackedLine(fill=True,
                                   title=TITLE,
                                   disable_xml_declaration=True)
    line_chart.x_labels = times_data
    line_chart.add('Temperature (F)', temp_data)
    return render_template('index.html',
                           title="Welcome!",
                           line_chart=line_chart)
Ejemplo n.º 29
0
    def profile_svg(cls, profile):
        """
        Plot the altimetric graph in SVG using PyGal.
        Most of the job done here is dedicated to preparing
        nice labels scales.
        """
        distances = [int(v[0]) for v in profile]
        elevations = [int(v[3]) for v in profile]
        min_elevation = int(min(elevations))
        floor_elevation = min_elevation - min_elevation % 10
        max_elevation = int(max(elevations))
        ceil_elevation = max_elevation + 10 - max_elevation % 10

        x_labels = distances
        y_labels = [min_elevation] + sampling(
            range(floor_elevation + 20, ceil_elevation - 10, 10),
            3) + [max_elevation]

        # Prevent Y labels to overlap
        if len(y_labels) > 2:
            if y_labels[1] - y_labels[0] < 25:
                y_labels.pop(1)
        if len(y_labels) > 2:
            if y_labels[-1] - y_labels[-2] < 25:
                y_labels.pop(-2)

        config = dict(
            show_legend=False,
            print_values=False,
            show_dots=False,
            x_labels_major_count=3,
            show_minor_x_labels=False,
            truncate_label=50,
            value_formatter=lambda v: '%d' % v,
            margin=settings.ALTIMETRIC_PROFILE_FONTSIZE,
            width=settings.ALTIMETRIC_PROFILE_WIDTH,
            height=settings.ALTIMETRIC_PROFILE_HEIGHT,
            title_font_size=settings.ALTIMETRIC_PROFILE_FONTSIZE,
            label_font_size=0.8 * settings.ALTIMETRIC_PROFILE_FONTSIZE,
            major_label_font_size=settings.ALTIMETRIC_PROFILE_FONTSIZE,
            js=[])

        style = LightSolarizedStyle
        style.background = settings.ALTIMETRIC_PROFILE_BACKGROUND
        style.colors = (settings.ALTIMETRIC_PROFILE_COLOR, )
        style.font_family = settings.ALTIMETRIC_PROFILE_FONT
        line_chart = pygal.StackedLine(fill=True, style=style, **config)
        line_chart.x_title = unicode(_("Distance (m)"))
        line_chart.x_labels = [str(i) for i in x_labels]
        line_chart.y_title = unicode(_("Altitude (m)"))
        line_chart.y_labels = y_labels
        line_chart.range = [floor_elevation, max_elevation]
        line_chart.add('', elevations)
        return line_chart.render()
Ejemplo n.º 30
0
def graphy():
    """ import data male/female from excel by csv file """
    data = pd.read_csv("update1.csv")
    plot_g = pygal.StackedLine(fill=True,
                               interpolate='cubic',
                               style=LightColorizedStyle)
    plot_g.title = "Like update"
    plot_g.x_labels = data.DATE
    plot_g.y_labels = map(int, range(0, 40000, 2000))
    plot_g.add("LIKE", data.LIKE)
    plot_g.render_to_file("Like1.svg")