SVGdatashapes examples:   Example 2

-10 -5 0 5 10 -10 -5 0 5 10 Δ weight [g] Δ density [g/cm2] (-6.3,-5.2) (0.4,1.8) (8.1,8.7) (-3.7,-5.1) (8.6,8.2) (-7.5,-8.3) (-8.0,-9.2) (-9.8,-9.1) (-6.7,-5.5) (7.6,6.9) (-3.0,-2.3) (-4.8,-5.4) (-1.1,-0.8) (6.4,5.7) (-5.2,-5.7) (9.7,9.9) (5.9,4.9) (-1.1,-2.5) (-8.3,-8.5) (5.8,5.5) (9.1,7.6) (-3.8,-3.8) (-7.0,-6.1) (-1.9,-2.7) (-5.9,-6.1) (0.3,-0.1) (-3.4,-4.7) (8.9,8.9) (1.0,2.1) (-3.5,-4.7) (4.0,1.6) (2.9,8.3) (-0.2,5.6) (2.4,-4.1) (1.4,-7.0) (1.6,7.6) (-1.0,-9.0) (8.8,0.7) (-5.1,5.4) (5.7,-4.5) (4.9,4.2) (-4.9,-3.8) (8.6,8.7) (0.9,1.1) (-7.8,-7.9) (-0.1,0.0) (8.6,8.0) (-3.4,-3.1) (-3.8,-4.5) (6.7,8.1) (-3.4,-3.0) (8.4,8.4) (-4.3,-5.1) (2.8,3.4) (5.4,5.3) (4.0,4.9) (8.3,9.6) (7.7,6.9) (1.7,2.2) (-6.8,-6.0) (6.4,5.8) (4.4,3.8) (2.8,4.3) (-2.0,-0.8) (-5.4,-5.7) (-0.2,1.2) (-3.3,-2.2) (5.7,5.5) (2.2,1.9) (-0.2,0.9) (7.7,-8.1) (-7.6,-8.0) (8.3,3.7) (-9.9,-0.3) (7.2,6.0) (-8.6,-3.6) (1.4,1.8) (-5.5,8.6) (1.1,-2.0) (7.8,-2.3) Group A Group B

Hover over datapoints to see tooltips



This example loads sample data using sampledata1.py

# scatterplot of mixed sign data; crosshairs at (0,0); superscripts in labels; data points have tooltips

import svgdatashapes as s
import examples.sampledata1 as sampledata1

def example2():                                          # scatterplot example

    # get some sample plot data...  eg.   [ (-6.3, -5.2), (0.4, 1.8),  .... ]
    dataset1 = sampledata1.datapoints( 'set1' )
    dataset2 = sampledata1.datapoints( 'set2' )

    s.svgbegin( width=400, height=400 )

    textstyle = 'font-family: sans-serif; font-weight: bold;'
    s.settext( color='#777', style=textstyle )
    s.setline( color='#777' )

    # find the data min and max in X
    for dp in dataset1 + dataset2:
        s.findrange( testval=dp[0] )    
    xrange = s.findrange( finish=True )

    # find the data min and max in Y
    for dp in dataset1 + dataset2:
        s.findrange( testval=dp[1] )    
    yrange = s.findrange( finish=True )

    # set up X and Y space...
    s.xspace( svgrange=(100,350), datarange=xrange )
    s.yspace( svgrange=(100,350), datarange=yrange )

    # render axes and a shaded plotting area
    s.xaxis( tics=8, loc='min-8' )
    s.yaxis( tics=8, loc='min-8' )
    s.plotdeco( shade='#eee', outline=True, rectadj=8 )

    # render axis labels with superscript, greek char...
    s.plotdeco( ylabel='Δ density [g/cm2]', xlabel='Δ weight [g]')

    # do crosshairs at 0, 0
    s.setline( color='#888', dash='3,3' )
    s.line( x1='min', y1=0.0, x2='max', y2=0.0 )
    s.line( x1=0.0, y1='min', x2=0.0, y2='max' )

    # render dataset1 in red data points
    for dp in dataset1:
        s.tooltip( '('+str(dp[0])+','+str(dp[1])+')' )
        s.datapoint( x=dp[0], y=dp[1], color='#a00', diameter=8, opacity=0.6 )

    # render dataset2 in blue data points
    for dp in dataset2:
        s.tooltip( '('+str(dp[0])+','+str(dp[1])+')' )
        s.datapoint( x=dp[0], y=dp[1], color='#00a', diameter=8, opacity=0.6 )

    # create a legend...
    s.legenditem( label='Group A', sample='circle', color='#a00', width=80 )
    s.legenditem( label='Group B', sample='circle', color='#00a', width=80 )
    s.legendrender( location='top', yadjust=30, format='across' )

    # return the svg.  The caller could then add it in to the rendered HTML.
    return s.svgresult()