Pygal Scatter Plot

Pygal is a data visualization tool that offers robust and interactive capabilites for visualization. It can be coupled with applications to produce charts that can be interacted with, offering better value than the base matplotlib package. This series covers the implementation of various charts using pygal, starting with the Scatter Plot.

The code below generates random $x$ and $y$ values

import pygal
import numpy as np

x_vals = np.random.normal(20, 10, 100)
y_vals = np.random.normal(30, 5, 100)
data = list(zip(x_vals, y_vals))
data[: 5]
[(11.062614243939043, 34.591673245423806), (35.130851896270485, 29.539220426850484), (15.158628632268226, 26.77690740370388), (26.539807983939383, 30.202201177428623), (16.027588718398576, 33.88813556845673)]
scatter = pygal.XY( stroke = False )
scatter.title = 'Scatter Plot'
scatter.add('X vs. Y', data)
scatter.render_to_file('pygal_scatter.svg')
Scatter Plot181820202222242426262828303032323434363638384040-10-10001010202030304040Scatter Plot11.06261424: 34.59167325252.75222305523792130.0097003498796735.1308519: 29.53922043517.7226246831074238.8728530445749215.15862863: 26.7769074297.84578550159273298.3912919548626.53980798: 30.20220118423.14268955302003224.587875574124916.02758872: 33.88813557307.41228165916425145.1685414720743722.49996033: 24.09247697378.66747405612176356.231626336545135.48963439: 28.22422284521.6725084832627267.206573030052824.59749463: 28.39838122401.75950578793265263.454052982364630.2923224: 33.13110836464.45461556485856161.4798998593098519.53631897: 34.67752925346.0403556159111128.159795743859328.132759905: 39.09824668220.4970703430140632.9083893928606714.71284659: 26.39054027292.9381121895575306.71618804996064.314410992: 20.48049503178.46036372731564434.057536941279712.38662251: 29.83475052267.3284046233293232.5051859588842325.7287935: 27.09784637414.2141241860222291.4761501252724.81577296: 28.58833879404.1625606132738259.36111422545855-10.74780322: 25.3658431412.63846153846154328.794921532001914.47926223: 29.19318528290.36655116161336246.3287319815419235.67997275: 34.20050383523.7679685822224138.4380691384656624.18758802: 24.75798321397.2467898225468341.892233068931211.62454551: 30.79974421258.93859847779817211.7128581377065213.28614327: 29.20415897277.23134727580094246.0922864277950516.72975185: 20.52744726315.1424881276804433.045876154842238.589698986: 32.8066055225.5275729313792168.47183134469115.07356856: 26.37835842296.9093479487026306.978665442120717.7080756: 24.23204581325.91298334234114353.22439308479546.618401573: 30.07652994203.8252998092723227.29566276269823.233655619: 29.94840868166.56218533724635230.0562396817335328.27688395: 25.73297221442.2663878824295320.884540413288530.75425609: 32.5197284469.54010442948913174.653056011154618.67953234: 29.74515558336.6078786804163234.4356518677635735.04358347: 34.87935991516.7618750868389123.8110324685236511.860541: 35.23183514261.53670389636017116.2163915456517310.66432333: 34.29079697248.36738582732082136.4925593943986522.10565933: 32.72289898374.3265624001046170.2754219309947525.41027619: 17.22903702410.70752514085456504.1153846153846420.32514748: 32.22159139354.72467269646535181.0768933225003818.32182165: 25.44022405332.6697944388836327.192266233505520.61066754: 30.27805984357.8680006912099222.9533797642960719.12700907: 31.82457048341.5342090083168189.6313419121517521.35743746: 25.05426785366.089289228217335.50830810928820.5954013: 36.26233423357.6999325913488494.0126454357476914.50057414: 27.3623053290.6011768650553285.77796082950321.047984698: 25.15562755142.49984598679654333.324351715835617.69932835: 31.897021325.8166836784158188.070279968375985.79358035: 33.96547758194.74473421002725143.5020845760452621.71169458: 40.16680412369.989352529967859.8846153846154159.149001021: 35.14910636231.68500278512607117.9989150228623812.65015124: 26.13314948270.2296271465218312.262083051899519.27497646: 27.07726763343.1632014556808291.9195519048568632.13982148: 32.40896728484.7939765187752177.039580845578716.87562564: 36.01665933316.748431965096699.3061027751234612.94880804: 30.1496453273.51757927572004225.7202757621437318.64131066: 23.9476826336.18709110607057359.35145196725526.27504456: 36.39535838420.2278740983257491.1464278497900936.28445755: 25.431142530.4228214350835327.38795351922931.37844736: 34.74668893476.41190840808395126.6696401852946123.65946838: 25.55503935391.43265110763485324.718387672359427.57266942: 29.52360616434.51359731353335239.209287289701311.81602645: 28.00161447261.0466373815592272.00302522547228.42230378: 35.97120999443.8673339608524100.2853814535176926.48799221: 35.32707643422.57224283480787114.1642660845025746.65209767: 24.98393072644.5615384615385337.023833776607424.01968942: 25.27338687395.3983720574789330.78703949022455.845505392: 35.06496686195.31638384467695119.81183472487012.896489768: 28.09883806162.85028202919798269.908188024974823.30021329: 36.14766589387.477564460243396.4833575321313828.37905536: 24.38357258443.3912063853895349.9595071871757518.02236591: 17.62604878329.37304679684013495.561133119824322.7683946: 29.14225418381.6227023333963247.4261239200324729.0296838: 30.14845834450.55406064872057225.7458507091661220.8086016: 39.34944446360.047082827903427.49593269649068425.70053225: 35.28397966413.90299235653856115.0928545869521122.93105977: 39.11706059383.413504646093232.5030136760072410.84088277: 26.15581383250.31115201100286311.7737434674021423.286: 25.33417354387.3210884346767329.4772937438700610.69024521: 24.39594897248.65276321123312349.6928380313607422.53820533: 33.54275795379.08851833981845152.6102529969854812.55200352: 29.83247495269.1491059379719232.55421675520829.703395124: 32.51906517237.78840055226766174.667346255709056.935713721: 29.02319653207.31863107806512249.9914108635309239.95581599: 31.57336802570.8412905948716195.043899363708216.26670823: 26.67822981310.0447798972607300.5174580693168313.25139597: 34.68015019276.84880970379936128.1033234794891223.61453767: 23.87913826390.9380030102074360.8283489569048521.31101787: 25.27454337365.5782497585645330.762120847157617.71023167: 33.74826548325.9367198160824148.182265586907626.22560283: 28.946626419.68356355527516251.6412448543504835.94458914: 26.10851273526.6811652512957312.792920925630620.49710687: 38.23696493356.617796297936851.46607809733336625.59340425: 25.73618427412.7236060491609320.8153313699209519.9946994: 32.0128059351.08672622083503185.5755097012025221.01152442: 26.06798011362.28108689705755313.666260965399823.63893311: 29.72059609391.2065755968235234.9648251804849822.34535834: 25.57769587376.9654404007534324.230216802321831.07683162: 34.28887503473.091380989139136.5339707243676323.86763171: 33.98256062393.7243486287444143.134003106658613.34841213: 28.31782467277.91687338956245265.1897721976033628.20091131: 37.54486443441.4299950516829766.3784871167958425.06902242: 29.39901619406.9506173847439241.89377689001452X vs. Y