_images/toyplot.png

Tick Locators

When you create a figure in Toyplot, you begin by creating a canvas, add coordinate systems, and add data to the coordinate systems in the form of marks. The coordinate system axes map data from its domain to a range on the canvas, and generate ticks in domain-space with tick labels as an integral part of the process.

To generate tick locations and tick labels, individual coordinate system axes delegate to the tick locator classes in the toyplot.locator module. Each tick locator class is responsible for generating a collection of tick locations from the range of values in an axis domain, and there are several different classes available that implement different strategies for generating “good” tick locations. If you don’t specify any tick locators when creating axes, sensible defaults will be chosen for you. For example:

import numpy
x = numpy.arange(20)
y = numpy.linspace(0, 1, len(x)) ** 2
import toyplot
canvas, axes, mark = toyplot.plot(x, y, width=300)
051015200.00.51.0

Note that the Y axis in this plot has sensible ticks that cover the full data domain \([0, 1]\), while the X axis also has sensible ticks that include “round” numbers like 20 even though the X values only cover \([0, 19]\). In this case the algorithm for identifying “good” “round” tick values is provided by Toyplot’s toyplot.locator.Extended locator.

However, let’s say that we prefer to always have ticks that include the exact minimum and maximum data domain values, and evenly divide the rest of the domain. In this case, we can override the default choice of locator with the toyplot.locator.Uniform tick locator:

canvas, axes, mark = toyplot.plot(x, y, width=300)
axes.x.ticks.locator = toyplot.locator.Uniform(count=5)
04.759.514.25190.00.51.0

We can also override the default formatting string used to generate the locator labels:

canvas, axes, mark = toyplot.plot(x, y, width=300)
axes.x.ticks.locator = toyplot.locator.Uniform(count=5, format="{:.2f}")
0.004.759.5014.2519.000.00.51.0

Anytime you use log scale axes in a plot, Toyplot automatically uses the toyplot.locator.Log locator to provide ticks that are evenly-spaced in the logarithmic domain:

canvas, axes, mark = toyplot.plot(x, y, xscale="log10", width=300)
010 010 110 20.00.51.0

If you don’t like the “superscript” notation that the Log locator produces, you could replace it with your own locator and custom format:

canvas, axes, mark = toyplot.plot(x, y, xscale="log10", width=300)
axes.x.ticks.locator = toyplot.locator.Log(base=10, format="{base}^{exponent}")
010^010^110^20.00.51.0

Or even display raw tick values:

canvas, axes, mark = toyplot.plot(x, y, xscale="log2", width=300)
axes.x.ticks.locator = toyplot.locator.Log(base=2, format="{:.0f}")
0124816320.00.51.0

Although you might not think of Table Coordinates as needing tick locators, when you use toyplot.matrix() or toyplot.canvas.Canvas.matrix() to visualize a matrix, it generates a table visualization that uses toyplot.locator.Integer locators to generate row and column labels:

numpy.random.seed(1234)
canvas, table = toyplot.matrix(numpy.random.random((5, 5)), width=300)
0123400.1915194503790.622108771040.4377277390070.7853585837140.77997580811910.2725926052830.2764642551430.8018721775350.9581393536840.87593263474220.3578172699580.5009951255230.6834629351720.7127020269830.3702507547930.5611961860660.5030831653080.01376844959070.7728266216120.88264119063640.3648859839010.6153961784330.0753812416430.3688240060020.933140101983

By default the Integer locator generates a tick/label for every integer in the range \([0, N)\) ... as you visualize larger matrices, you’ll find that a label for every row and column becomes crowded, in which case you can override the default step parameter to space-out the labels:

canvas, table = toyplot.matrix(numpy.random.random((50, 50)), width=400, step=5)
05101520253035404500.6513781432270.3972025777260.7887301429410.3168361221690.5680986526260.8691273895610.4361734238960.802147642080.1437668245150.7042609711180.704581308190.2187921056740.9248676286160.4421407554040.9093159589720.05980922277990.1842870838140.04735527880150.6748809435820.5946247799340.5333101629990.04332406269480.5614330800630.3296684456210.5029668331130.1118943175740.6071937062180.5659446430510.006764061990.6174417088040.9121228864330.7905241330570.9920814661880.9588017621530.7919641352920.2852509600250.6249167053060.4780937956710.1956751786660.3823174520320.05387368514620.4516484082610.9820047415220.1239427004870.1193808979260.7385230561430.5873036334640.471632534320.1071268171940.2292185654610.8999651948370.4167535378030.5358516625320.006208516587130.300641705770.4368931721760.6121489970660.9181980753810.6257366699630.7059975650820.149833715990.7460634091370.8310069924340.6337257689510.4383098811220.1525727746750.5684096152470.5282242775850.9514287637540.480359178510.5025595633830.5368781929240.8192020670640.05711563808890.6694217430750.7671166283790.7081153619780.7968671837250.5577608284270.9658365319920.1471568998930.02964700053540.5938934926250.1140656987430.9508098500840.3257074144250.1936186901540.4578116488970.9204025710930.8790691615150.2526157550470.3480087928690.182588731580.9017960513710.7065281631720.7266584615620.900087836810.7791638007690.5991547806040.2911252448980.1513952644070.3351746591490.6575517771580.07334254363260.05500639540620.3231948139210.5904818044630.8538985671260.2870624250.1730672268150.1340212059990.9946538286440.1794978694690.3175468230270.5682914046590.009348574500240.9006486211550.9772414309230.5568946791370.08477384339420.3330024657290.728428676370.1424353733420.5524689394980.2730432596840.9744951380870.6677869061450.2556532864340.1083114941830.7761807231740.78247799260.7616039143070.9144031132690.6586227819420.5683675815730.2017556924530.6982963755520.9521954098150.8899632871420.9935673628630.8187035102040.545122166180.4512540549640.8905571879290.9732647911190.5934113295690.366074497720.3230946929660.8714232550490.2156340629880.7349451885620.3656190873670.8016025985030.7827355919750.7013553792370.6227765866030.4936826457470.8405377001180.7120969869440.4439089814160.03103486113330.3632397601940.730721791410.4755665730840.3444169701220.6408804349960.1262053216140.1714652609640.7370864936890.1270293935720.3696498749470.6043340048360.1031044388560.8023741823370.9455532358420.9790388199340.8812322463390.6276819214640.9304865334030.7247899531020.7166778860550.04107856658420.4394817751670.2820697831160.3349959688920.08352700704440.7608491470570.5092724471640.6610474176080.6303144424840.3709268274580.4467401517310.4151082201980.4803885080130.9833235733880.3734237073540.01240698172770.9219033377990.8732760703440.3517468215880.6301331125020.3578269593420.2128199376480.2233192231230.4195637917310.07291022107810.6508390701370.7556861489510.9321012263120.3764041595820.296927283450.3719443124940.8276993588040.901139535250.4273037848570.002189430823120.04196524456470.1417873831630.5982371851050.1064605220120.2971589861740.05839198991210.6213248602510.02268047612480.8550546861320.3063372028660.7587834447540.563275110140.03816418217860.565516724060.6588734886480.1832663493930.7974113080910.6123674294690.555653384450.6294915446220.6861800753310.2403825375230.787927787980.856477457060.7277960155990.6923451434160.472350939070.8568729419350.6647433339040.3333759422750.5181454992560.3946885834450.03104959835640.57683984313350.8502517453490.9514888651740.6829787971080.0761625481960.4100779427720.04190139877170.1741868315750.5654020055650.17289117060.5666104779440.514004252950.8688708875470.7203472479310.903591347070.2776149982330.2566654321810.6997032628610.9015688962490.9836923251220.6409128124260.3300073885350.6066752162290.8221597885760.6279650654610.1179230575010.2858776733510.9867472153380.4318008484910.5742344137830.5272420766740.1976530493780.1657084322250.5009904579220.9902040600850.3939918113090.7140132652770.1759042694230.07069617875040.1576230863120.1615580135090.2836370822620.5367060255640.7732387148930.8803435812770.6373914469570.8526022402550.5979553715240.6938466603020.5371766731470.8892300834660.05226642625680.7831837007930.1451732691020.05869842598790.05899458085550.0519712298680.5159860884420.4049962200990.999649593770.1085700105530.3273843024950.9978299320580.4011143917380.8833357664730.5691385805270.9532408896440.8853872441550.7792855915820.03180806303620.9626185297830.5196354442310.2077910114540.8750978067390.2241514790030.1386593265370.7252392875060.9737889095070.5354818765950.4447979980.02211117801850.6059883403150.9647965239570.9675914809670.9300288092610.1846798319960.6229621583610.4129626697630.3630612022050.03660294134480.8681487095720.6728282126280.08747161406170.8869659392360.7824645507650.3173044112630.8183137873870.5075550682420.02119330176810.4335217582290.4463130559540.2388199894070.8302457318410.7447641766130.586479000960.4928678525650.4873558798410.2667406959230.605011101440.753543720990.2705842279530.5223032831320.09832853021360.7136366749690.8840405940160.5670544212280.9944815788970.1787397702630.01220008629440.4569984805570.9317519418550.8460246882180.473329876070.9025550260480.2259955263370.3041537386570.7149938815140.7240914834380.01867643942370.2858131033590.5804863352450.930786632090.3389969016790.120083123070.5162727085260.6992070633110.2986406770760.8616096152790.9058071953930.7685832518480.2612316407380.9384555961970.9386424555130.7450445471080.9107350428470.2372247087950.494967352120.809878338810.9545657838250.6374832545240.9108497527260.6921367511960.04294298934910.8335869006880.3699485159760.9365570009010.4830528751770.1253316071680.964454183760.0170258309760.6765707650770.1404399662110.1553128532830.6495577470550.9816542161380.6948074153820.7619738930360.4252091828030.1388934439670.216186303160.7647002723990.05460586915460.4901229891340.1806901817050.6309248464530.5512420333570.5670812144840.8183449753360.9389873038060.1929014148640.7128440242920.6979398042410.2582964987040.9158078195670.5323581865770.5579644194080.3227722681650.3386307825990.3323015540420.9788182055930.2032151955420.6670260600650.5747842669420.05197528656950.542838102590.2079491149390.09109017971490.8698557120090.02736977949690.9686245221960.3274998895750.4102779578680.1355442150460.1270663107450.4139839797640.6174437360390.1322669028670.9744812178580.1806351024450.7603499111960.4821618152040.7680788681440.302898442830.01517509077550.4633686864670.7033370789190.06604089290970.6690114176570.3454790558420.5917214726030.2290534578070.2675683624780.932826985640.8261450587840.1454431928340.6470036098930.8839511653330.7413605341560.5157107993450.1352518435650.03988365260530.8343218320890.1170578692950.523102313610.8730584682570.03870783696630.6923907867940.4762684781330.1692644884580.0631718922520.03222409195180.242430856380.1127068246740.40499001740.04207297124270.9265654494020.9352629086040.810426897490.1883430784330.5873182233910.903510555662100.9673422647360.06753921493330.3175860717170.6968629710760.640265375530.6326233136490.8287506490790.7131104267320.3354802271650.1676946768410.7646898163210.3593150624810.08800478164560.7295675996420.8810499283810.04126388119060.1748677614660.42009741490.3406065793030.04476891580510.1128913139090.4380414878650.07107320402360.8162451076570.8661156482930.1311198419190.1932194496740.4374927517740.9709253246770.7738609642780.1317764717090.9271798636810.8277965797460.392731665360.1405706461250.05213633919290.09272931541880.8869896303640.1681509672160.3628866119150.6542818857560.604821953360.3949928722460.3746054001920.06307277176850.4289590278320.7197209260540.7680308900380.1943681456810.8628707690920.02872195327970.9021288166620.2365458799230.1285842607310.3178757880290.8487612955160.8322977467110.3456513524820.2399711883370.5357875534880.2714669358210.03443087444440.6270855902210.5202004609460.04195581410040.7574727689590.9883497629560.8014009582230.3439810863260.3353912425090.3515714029980.4429456793480.579493435220.6175609092360.1771174879670.8649817885470.7102706906140.1706316884350.8550826592840.01985662193920.6416837319890.162334352670.2575504904810.342606460020.006144141992960.438551060570.7970441109630.6756649386860.5450230881420.5642269921960.01398414927290.6089771393980.9885663803950.2241070236780.5872177182050.8350579495170.7924975757210.3292279954770.3572025597720.9601129626330.2237955926380.2115367109110.1539151651550.495895845180.2612947801740.555686443060.07291600406350.378516838640.4610890262220.7785404459050.7204427175950.2312044810510.02454439227040.2573649409140.4101160298820.008398995643330.4715489466790.8524221108560.9231796983490.2314361339140.9909549144770.005997896445690.335250522370.7892581129430.09851151520560.4423322492790.3806693244810.8325984691060.7119621853450.3550008257180.02463633449660.6935125189270.4212119413780.8583494431990.575073553790.9400623621610.8802555194340.4581450305530.01731006753210.0686546413810.3206080161380.5923018868750.6100524383180.5124275033630.144756458340.8768086932030.7382351791730.3733203838930.8286863831260.09023953749160.06400321872230.5058969484670.9334267114350.1489619179570.5694787932070.05974865497540.1692779268640.06902836007910.9060224510890.4474100602510.1063852005710.6652597785270.5022733771440.4092063820530.7279934703380.1720904092880.3844608916020.2670011375180.308220873570.1773028029580.4825584777230.6297171958690.05955332382440.1968872684390.2792084352320.7078206081120.3274290852160.4252940439040.7047675006820.1590771702640.4394038888850.6293299859510.9250580996440.3569879633420.8191334467440.6401427896570.7150524930760.7384225168260.9709996125780.2460492375650.04258158034560.2477972735060.04501663674260.7054616268670.8347067705590.9341358550240.4707933558960.5123595171360.2629804767740.09889670914190.7988463567840.1428027763660.8056657855850.8795261009330.4999201641960.9142519408680.4124125914570.2003735872850.6435711085760.3998651431050.6142314979390.4373113967010.5931037466560.9514400107610.5531204339170.9037353572240.1385047548720.001543762571180.6128343455240.5417029302330.7806306585260.8214939537020.9534097561380.6099560916570.2900818218760.8268079939180.3760168937260.6091770259290.6200215567210.441499969910.1987718953130.4439536209140.9247673443220.6714343597060.08152309662890.5726592489590.1206621977560.9999637237790.997380347250.6947121427370.3738798440980.4015107889670.9250994130050.2448588417730.6640126803940.4812207510720.03494355891720.1108954619350.8953693799670.892101138017150.9151609878090.3074016709560.2984196298370.6592518589260.5951377226080.9843690116520.6156222569230.1547163276220.831469465240.8156970708360.09204187578390.8877899028870.01643905811570.8639301134710.8987706904730.8503665670170.6528693628590.3287552409650.5453793289990.2379351681530.8717846579430.176733742260.3706358671570.7595845287790.3061839090090.6161392549620.2192911749730.8725236662950.6478649091610.4730029447560.2341903211310.833821813060.09851632452770.2050268601620.2347305737760.596973772510.6284675409760.9826510416190.1763166657910.7999774129570.1552640067680.3609919582260.955075256650.1301583678550.2728465851520.8091178680740.9656570566740.09242216403040.5834242702090.405426306330.8993241878490.08478344556950.1811362766060.05066547368570.301278738130.1901838543050.008605387212870.1275229006540.1128647238170.7304144514690.2393750328370.9015701210380.3285139297530.8740427227860.2365295149870.3784546056690.5422905579910.5157939822760.4138021181790.3888666129030.3403308179240.4022346302070.4571098967160.38299105770.6580897273540.8812142062070.5726725843310.4280404570360.2583779332060.8652694331730.1732783007370.5799528248240.7273774983780.7304023353510.4039958160060.1179274709850.7635946309190.5336610922320.722034858760.597632335020.4228659699880.933486087660.993970993010.5478388389420.7302345718430.02798428506480.8635912766430.998630759360.3253098239430.8502608344690.6114921194050.4411130797350.5272045872080.7798206115280.2513501934120.4628923211730.847186672060.6780235943470.3678622934390.137983009330.4028094476040.9312970923620.6731627853180.4192298153720.5686666120630.04171068434170.9956341275490.6190042191160.7794661237760.9313386353480.3416185604630.8112991994740.8727098022060.6659882250670.5887865481770.8933522602990.4485840187540.2443835793760.814172964330.6971493985840.4096045410440.005715084265160.9540143640590.6052525996210.00654627659880.4984934870490.5986353460190.3001474501270.4617574961690.4955997811560.585659140930.8696379884570.832226959180.7785630480050.5484331076870.6134519565060.7342697271310.5663690914040.7752101347160.9865456057640.7892056896960.6143359816660.1582845392530.4763863142140.2836491734460.1538122652520.7772204195290.0589631333940.07912250151510.6642384626890.5233449810510.446406889580.3068304470350.0172851213830.29352684140.2677939656120.03672560166770.8040395779250.3337995572950.8918866845680.8103532335210.9641012075430.9577140638360.5911655049280.311503319370.918420730280.05065045623140.2257426813930.3627060986740.412255701560.9446212956880.5793825450260.1867601511260.5964846652940.9337562971860.134138140360.9822835302870.1538756532230.8207281374580.6775364747470.4040892596860.2172870413510.7735847352320.8476959291310.5296996198710.4095997195120.01830794664770.1486596128510.8043351900630.4197781235980.3392175702740.2971458504720.7179859935630.9978071813140.5519022755390.889896045210.1684682870640.8835642961540.702775637410.4221086539450.863314947760.2350432261430.563750663430.0265602509370.3800514541370.3618350970770.09124352492980.04525353373770.3424515132950.3554139753160.9958382380490.9442045718530.1311441118380.5183550554750.477245375350.4011064086610.9306144016650.515336146950.8095820185970.8817722277750.7626677820710.4644207021820.07391960466040.4704993578740.2005719774580.2085672235960.1775396001990.3542414486210.9117531262170.4335209190430.178295886320.7521622490760.05047056570280.08266851738550.03858344154490.4652786064830.6038286634960.1817893432050.5190297006210.710153275864200.9249803784410.5291316448880.9711857323250.5472527610160.006437978516890.4727767485290.5220880797210.1522089080880.6542340841140.1304436301670.454148873710.9823614509250.1325140941530.06027892124660.06787227828210.09614604704290.8193423749130.6296065042230.7836310051410.07713540276220.9719983107660.8828335629920.630433129150.9290730885440.398126605650.4889260966340.6858032342910.2815965798560.6766999542450.4957317128910.7911419816730.2188335309510.7461958365710.4541110469320.4082623269370.9226434859040.1507206435560.1309828513510.3818900766850.5419866031190.944370158420.3232587694040.09744197863180.9473872596250.8570348216050.02603686378860.1178936820240.8293763805630.1384742905350.5694711357590.4777754141770.3066864785270.0566070787010.9368352083810.9040036022160.7222354173360.6540781789570.3922099366480.973674794770.7110076052860.4930483701260.3264414844570.1158530589810.9720606982320.2744282758190.1874496918410.2148951324770.7608539887710.9448893160130.5015505546960.6620835965020.3474042244380.1285699957420.6812962695240.391283316250.02620447388780.5005996963460.5281271090710.2232680417390.001689681956850.4465634820830.5053258133320.08101884639330.8227399059630.2401949305310.009690276665460.2250417345690.08419013702150.8259645989260.714767218610.2445561377950.06383683930490.4267541951920.7060415197210.7181535785080.1934343349960.7400481010320.9567298738210.5158939771340.430045228870.02303675507330.5073259649790.6865622277390.1381752619590.6724228622470.0393114612760.4317765212720.8542758466010.4223284835720.08844911066690.0566950076360.1032728455580.4853156973870.6746571718890.09089484368420.8322123064490.7764635309150.06116335833020.3224178617270.3771396984530.502265005910.4499653551840.4673620054540.1047144101990.373750810180.02177226195830.4483377681510.8931148081880.7758812238560.2491613153960.7315445113970.3151379752520.4961304607220.05042585021250.5825199970990.2825940187790.2933359729380.1260540860860.8931809199830.4512730805650.6508714207840.809305166670.282962863510.2733817903540.3857371886430.4216081234420.9321654327250.8676328206930.4451744272810.02918941948960.1071982425210.1962591461840.2382363435520.8245104457210.8964855865820.02788720753690.5733013273960.8056431107890.4205124329670.5252668365310.2861425930330.6586462326170.09030040914870.8222653089750.807414288270.1916166742180.6383030202990.8324646156680.4698270922460.5803530332660.1089027799070.4624194899620.886351832890.464982774940.4662152714790.1960046686890.03872888864450.6158617561380.5646312804790.1082308185880.7416331879390.1834820261350.3486410919560.4804814932640.6439264322310.6216264254530.7611930091720.286651055390.4923852052850.6819101885120.509969856240.7682113644150.2999364415080.5468807525130.2446449314750.4435972913170.8100144628590.1038669124380.229984738870.7917644077390.5665413285250.8274172378440.9749337447570.9652244749420.9497026002330.5517869164090.09253612840320.7404307729590.5642974448170.7458577285220.4553898863460.1556629999010.9959528409880.8896910862750.8037493991740.4114757110760.2131568558690.2944397842340.622931339660.2482170512580.7996809419990.01888223178620.4803513902070.7340152908970.6835678945990.4212829685320.6932033372870.3671976984410.2324414071390.7850505645580.7267051581830.7064572601760.03174151035250.2394387395340.371057572210.5818787334190.08798869054320.2321289590520.8125159823760.752740373140.8047768995810.2944433887390.7806189998360.2247863033090.2898491519350.8489818763940.7441655113280.3322531779180.567334378570.699648463616250.09193547440630.05380222577590.8627961680580.6299703832590.8696531517180.08769087485840.8659038243730.04124756044910.9581740907350.2273680772020.7518621019160.4007486695220.4030754244170.2532869687380.5068384497080.1845601582520.05708402628870.3669265379050.7198372866510.4741745356420.9226202775960.1701223011820.7183817796240.8697976390440.1293097557770.9740558110840.7542156213910.9166774557630.03770284114810.285848847050.8229078779650.2747336299160.05172394804740.1479432812570.01649266920120.7824166228330.3491216074880.7496778456020.05495339221720.07819822366010.7893405249310.3704380528210.1109624423320.4052160237560.6512987809890.4362882072080.2024751508960.4438895804780.742148097350.09601509224860.5117212638770.843616444720.9935436520710.6307561774280.2854733297910.1260217578230.01335570314610.3381556210530.4843201731860.546191046710.03603937408220.06122445122420.02316075270220.5073894406830.2665910241710.4453057647960.9736092587220.7977763144060.2841255159920.5557863910420.1975879930730.7906008616460.08761964528690.8379254633870.2412625539810.434262314280.4278615772320.1021171795710.9088137341650.149011312450.907568022830.01045358055910.1735343850430.8391386545230.3102546368290.8489856755680.911343949530.8999011164420.8672286285320.8377621893220.2536428464610.8430081284270.617628091070.9841769638730.6105401468160.6516983659170.654465161890.5523273101940.1857301014020.9809763708510.0959366346350.748262880690.5246184102190.2907597249230.2281907525420.5037391609140.9319571618830.5741297777490.9897446158290.429773025020.4163557482120.6278773032750.9073683287060.06942273881960.5504031430210.1546058351350.7185608003380.1354069019770.004546466401230.5375161760590.01659280188430.5355145355030.04569206827520.1539793658080.8430104472240.7979294140480.3035943138830.3984933872480.4492941042950.02053517693130.6175541150620.8045548713950.2341720114460.4001283898860.4933141610.5018811189080.3334882091820.1054202791290.6408078376360.15146912390.1951766589030.05739145473870.914744547270.8306700912140.1590042777890.867706675490.5072982041430.128301370710.11311775040.2227977805070.8898369750270.4509220864990.6972096711120.3902901536620.6226237603790.7164481111810.5008592392230.7600812242470.8326037531660.5599436164140.5438525611080.5879719958040.02515425636050.9891018581790.07077422417610.8176151694940.1370357607990.1530196450090.3592416975150.2534624457780.2187643894490.5633834695690.4800623963670.0930468687240.5139065588290.1974177904130.480270340570.2770202544120.01048374407360.8877812016650.3738984675070.4162169962050.8775825001040.7607709251870.548112380990.9023409637550.9207013256320.4654408030840.5656467715230.02855803554410.1403306186250.3999981917520.8270977246410.4553913699960.6935832059720.6379803456240.6558830272420.7693189947220.0002272499141720.300695444840.6954714884020.09088742177310.5236475240190.8945950286310.9637058672510.7056881874670.7640288870.3446078584770.251850328230.6672091153780.1493050150850.4709166922780.02229193757590.759711055930.2056570799070.8405904741260.7748543323560.1761640451670.8845587905940.09306395402980.202188445430.3724054828570.1736557107730.3452337427250.5677384811640.1569519939280.7757404306750.03366157773190.01095851402730.3201233555030.5267271046520.6297265651650.8815138331180.6411391728710.02268791551490.6951902978480.8846517980690.7513941049550.2630779711090.5075744901960.1241910137850.608725692570.6933128037210.07778623174730.4040814974380.5134868894090.807066290410.09896631052180.4725317281430.567341848051300.5359836933520.1842628871960.5867830641280.785911035750.9980687158470.05272959838430.04267885407790.528934496340.6033794622460.08225341709430.7098156723270.1161383932650.1973024801130.7792854566880.4558789139780.3088496429130.3676757792990.7633076709510.1804474853950.1377428566390.5008608757690.01490253484220.3472942919430.3377372301390.5046312807540.492379125430.3502956175860.2023899980450.1599441123460.5610165214380.4461756149710.8552990260650.9111806228480.8765647930360.9654292256640.2023113059470.7263758589060.5713180162220.5839273296110.4567218973160.5821108435170.06774828417340.005950522622720.4680117494250.7902277425970.9229488579660.7202414025570.125931033850.7190924664720.6154942694170.3867184024850.7852140395450.1013440606530.402937871280.7423966768330.0124338113120.9281826700120.4602234859770.06962501845960.9099308711460.1233044999210.8947816630810.2050600226880.9319887858890.4979291388470.3600040566070.1608711928930.7263759711210.8352748531050.3188788957750.9780653647020.4727111859070.5661443961870.1466844092260.09974441817030.08651712643360.7530138272020.7422893000940.3155063586970.8453144272010.5345466575710.8325703544810.1860339848230.2759530257970.5830575947510.9299514621910.05729539747180.8182973477030.1646229744480.4397061056840.3665207606530.0657787877050.7878088794480.5123880597120.1768385041560.520831217540.5910090642690.4445386145040.1430080051160.9612641099210.4177697763510.1300251372140.6509930759030.5879054012440.2547375055370.2874328302920.8052788597160.05620762703490.2781916881520.9367113925410.8384065699760.908173854340.5946170874710.7735013194770.3440999943310.3838672719690.3779412330660.425964153050.7068978471870.2441706292730.177781362630.2164654639450.7243903983110.6314870192910.7945349037560.7857185138310.1449773238120.08748815434280.2567569243960.6401174123630.5697078901060.8893431953770.9181418657880.152384939190.1189850051360.01005364473480.2798394884460.1229221110530.4576360746830.1884014853690.007611474479910.8963379768880.9975529488310.8060040536970.03016793332170.5353234844490.6100005010110.8514236401170.4099580038580.2613970253430.7547909819880.7910759825690.7872897029490.9477818685750.4002082359110.6582163823130.5256362077390.418142905590.4075353156980.3712689063650.8438943742890.4708260777250.5848995929140.1657180216260.5471582435560.5388185215030.5076299540230.64308088330.5446837367780.3182544458040.7881913396180.5644253356480.4155788602460.3279306622780.9206481386720.93046926480.01069175171850.09308227907490.1340894436040.6273370243370.2616917253880.5825429574410.55490198790.200340664290.6570801200170.943206887030.3567676840660.03180126608140.4735270391410.06745759228250.4992538619660.6921437310030.07611761605590.2298300295990.4973678672040.5427907267340.4949348945440.801282967080.3079592628790.1140197787520.5602810387810.7691088502220.4351869255790.08353388599620.5985938686860.8460641374190.1832556713660.9129691913860.1036522644010.1268238116330.004074416859440.7845890290730.5604784494180.6605201366760.5218222595950.7957461473260.2516441516260.530481504940.05630425079090.1373325054120.1419880626540.6637679577630.1078395217040.7570345642030.4542549338780.694127657480.3567273745190.7680177173740.8173277408580.9267436926750.2070375642520.6009565230150.03447780495850.2929897686620.04230098707380.09726774777750.3009165064760.06026662113040.5831779199780.7244165704370.7507683005650.6980994014340.1133587734850.2869594189780.2621446034390.06622806443390.002176949927080.2693443996640.03381079383210.467862474748350.5408265535520.2047754769620.2287983991020.6533310872820.01962190999690.2994160989310.4804155782890.521273713270.958998050970.7606797150790.8034264080720.3295606254470.3767791071670.6870566037040.7072528680230.1108464913450.2677527460920.03053277356720.4009939693720.006122207673890.6688717088780.8688992714180.375823073860.2811104320310.1013506369490.8057157910740.4842741159330.8766750471050.152221739630.2197163374330.7332710958260.06552056587770.8155112819180.859773142630.03161053166130.06680324304340.473045075060.2056177635040.2254437515890.4343785651060.2329099889440.8284089380450.8914419297950.8143067856550.961299989970.6638473502470.04595686944890.8755535919140.9429501741110.9691058121350.749301322830.932736397270.08841157925130.8343467619830.7313805831540.9614458216450.1146670797280.2634809010780.1974276746450.145589468050.2695523070080.0839051324020.1957436235450.9475191877080.9697370164030.003896646561710.1842929394650.9279660961540.6865002838980.8147942357470.9900788638560.08069005318710.5735117469620.8665184332120.2464051513690.5933351726480.9758620149230.1938111578850.2929365118720.4964197500720.6537520302220.6066126057850.7078742814660.3142008808390.4458535105980.3010898113360.4372838430680.05077463072630.9535113879070.178893417320.07675271822580.9367869378510.835824860410.9726186088780.8231748373710.03310361888250.5694970685870.1475150679750.580054033610.083490604720.4552872755670.8591571086960.3255764319790.337594996690.9181365195990.6372031600610.1659506564190.87412316550.09556686693950.5901226719980.6327496961070.3326548513390.1611801277030.6407745632210.3877399558190.8165278563550.2293197123780.665116419370.5756074480570.07937200227210.04232201549810.8570224970630.1475421370180.1030777060050.1063487523020.2932515568840.5301168250890.866325520810.8687837464760.356503301990.098127461260.4382272861940.947486232990.04159501978010.3108475570680.7822869120630.7955101481790.852580649110.5438910620410.5906285703760.1391079725230.03472366239860.1552595760690.7569194736330.3687824263460.2828123633790.2417987207160.871351917770.3670943852440.8880357791650.9498786592620.8727589024830.3720453721210.6458568238250.4326905405840.7306004196580.6989447597920.4302683947650.4038717881810.6011060573520.6488855055770.1140795173670.7053510929690.3597290693570.4229263849470.3135421659090.5683060501390.033565019410.9768400696070.970589211270.2822726492870.6578207516140.7770859922410.945495007360.668108028640.4505201859320.8402529857160.8225205617110.9301825245110.7020578245260.8006254486610.958945081480.3858838718140.7325101027860.1285246948950.2053341366950.8831822328410.6958235611020.7109030722710.3697911385450.5782741947960.08380892496940.5941826075570.1769732675950.4208672281480.2398740661470.1275283612550.8956019867710.9100764736510.6288792202360.1575607313430.7305895437250.9890964232920.7797477593570.9795347138580.8049482782710.4197325477560.4650540934240.7563950299640.8101501692750.1413430491720.0811615475260.3575508529590.9687920051640.6917280065940.02263247595230.2128218910530.7262467040040.6732181613850.0383963678110.3586872946910.7511412546990.8656716461320.9542165029460.8795647581710.8659624942130.7120571217970.6637710342180.3847949517170.1793041326110.7445320592920.767023952250.156547452950.002301944997490.5216877117590.7585711260910.4411689054030.8885582573140.5293153195810.8849915371520.4526766172760.6839128557650.06119962283630.7405372463550.6725967456420.0103958002180.6732219005790.7899247960890.8307746189660.994382033653400.5670554841170.861561606850.09117119204940.1689131778440.3306072977260.9547285527390.1036983036570.4972331215390.9890876206270.6155336907750.556941726590.237430801770.4683758989310.4688477734010.5631276737570.4116600051230.1775369444370.1523286921090.7496345710110.48885554650.7292771104320.4249683859790.7256262356690.5880075040330.1370710542840.5647467875810.2944745847210.6339949202840.6432351052240.5525019151290.3900211551480.2671220471790.8021664190070.8996358935420.1015878556380.4537800488280.3940229103730.671643414160.5537935586170.8429087169520.005964701009240.6459078508080.1148565919220.7563752508250.228041283740.2185378617760.4113404369580.06849513104780.4687522377120.3544383527260.08270218202450.1358285580730.9127066908230.8719277258550.7836642589180.7148363688890.6703393976230.6341914384830.3906737834910.7666537196840.2217096455370.7067574326190.3045543597360.7837222024640.6059978555570.8717482634830.0859377985490.5456518623350.915545199280.6126614900530.5593317380460.3289048627390.8326044822170.2451665293530.2880223867230.6026081769590.3893001588160.4123107742320.5328529099380.8759270068960.7643135726360.8517179695520.8399686879470.5470905465420.5447416914080.008815275717230.6197031392710.9123700082540.212596008250.3221509969470.2616460970450.8933618819190.8224508056010.2616506645070.206883910810.526369574970.01742902071780.4173857570660.08902295402730.9872798881820.9494885806950.752156842460.6402643681520.2083777909140.1678661714640.143720169960.4528462278130.004471073000820.3147812347770.6104546867970.9938933598560.5215802129510.1026769004230.05239253973920.3285843328660.5597616914470.8377541508020.05611356546180.8949200755390.8957995066050.4522584734160.9049277940260.1531901978960.7364612217850.4747040674060.9741068255660.5256821598310.8581112948380.8188304585640.8385568270080.1883832976980.9248689451450.7063191579110.05878812075630.8836311928640.3377291688150.9958011273690.4620741824930.8109186947870.703422694120.9606795469650.7149308631890.4952138790320.9747446097290.7269469992680.4968954561860.3306205440370.3692281898160.0768644597050.7676578261070.9272810599150.4226648547810.5208931215310.00895410684770.430327394740.1530615656360.4813891545540.5022241365930.4911422159620.793016135540.04950112351010.71634067620.5512657988520.3444676001910.9414144036240.7533130216270.8012076340010.627031114490.5482848109050.7176082223480.5288462116740.5193114153740.2389709493570.7295448907930.9960752264120.6718740796120.5713389066970.3570993605290.06427347123160.7078196393660.2347927681230.7852742661820.3599547215720.07132198267950.7852049762190.3885021188620.3567674676080.5160932689760.832568066430.3016449513730.541365819280.3230266503740.1248231535550.1693838975790.08059412614190.4630165161850.8586334240980.1043552193320.8529875662430.5971230422330.9155838588010.1777162744650.9821025932980.6543839610840.1420177183880.08670490859740.4045652919670.4265880116930.8277470613540.6505773455360.0188827350150.9046821250.5304500882950.07992026004770.6246704618480.465972697120.3169795356160.2766354577460.9482454296030.7167804472830.2582648296310.3489106585080.4707684313510.03816733217210.2990565911610.3717655601760.6216696962440.02697277343620.9195484075190.2388659741960.1374101207320.9374218585560.7562191852980.9528881779830.8596590991090.8637226781480.4054972150710.6965075876060.1234938810620.9826197174440.2934091885890.05636382202890.9345407774440.6487795452920.3455824948870.5433103570590.8774913456640.870594962350.9765890834340.9813649182450.4358964552730.0843002358130.3771235604390.9452977728960.5208446231150.785690437990.8615666004890.4293753782510.6854403201050.2647641345770.1950037886430.8205174861270.5202841794080.3934949700020.041082441270.1209447511710.6974984889730.3263772457790.305887420920.8746243621240.8647115812510.7347657004660.2771359035780.3575384625430.2773514835330.6409935846390.1218152078120.372179789010.45053189360.3905607905210.8156835553810.9736441594770.9206140823420.09897951413940.1184535171740.980459281980.1444183626030.9032130813630.7459150101490.3484590339810.009343604939540.6612470925290.7761377764360.9266175831670.1094162175330.06988621676210.8878433635830.7059016859390.2158216510640.7225141714130.9790470339220.06029400370630.7149178162010.178969666670.8620102709620.6292777147630.3150534611650.2339320961350.6829518477020.6343710419520.5939899407530.6532779885670.1591687978970.8892912179430.4298081686440.923675663640.4592043141960.6295885143620.1218094835130.2306979856610.02049146630140.08292530151270.1620644915410.3472795004020.3835002235580.7166144893260.4807503548750.8727865869620.5080411149130.9830348403160.4262152871010.5220114297910.9467443623110.5148180982170.3752326888980.5571680173120.4552692070850.9445964033750.7470598569570.5927560788320.9345946192880.8579462493480.6244523197630.7671870920360.7984259089550.796431267810.09058964208030.02566048499350.3540533387310.2828015745460.0557165826420.06782435013680.1016797953640.6166963972870.2020654259470.8798322988420.9970083500510.7837187732050.7251943413080.2872131905050.7171009249140.6507333177420.1348639820940.06481096135740.3051914701040.6940898068930.5887571481090.7173069829970.873949960530.8053250402330.0988735857560.3069142518730.3087376738370.6401906381530.3340832995220.2152296959570.01840099143370.8629857333550.111205052620.2520687788610.9924696443680.8278759830850.2450556060070.05355148434690.2132061417780.6424788253340.7661732814470.7510224433890.05593320761250.6186491198050.3463200880320.1818441396710.419065536460.2787518257970.04921602964990.8337840197890.8138026515380.3469548621880.7517565051910.01913796574970.7184950667680.1409492245990.6555426829490.4352203618150.7680173087890.209410747340.3377961195940.5065786843330.2912001621520.6716355061160.02536598175630.3238168268890.09289728281460.1842267573620.8293701314930.07615518874970.5215675369930.9840663317340.4242390922150.6358259610330.4355683429360.5528289016670.7848888592010.1625030023690.5828403791330.5704191911110.1550156428320.2488843025820.1980529130950.2867892503090.5777195908230.575723406950.7721008450070.4098070138520.6669047384840.86831649580.3295126772330.05354784807670.7940439290230.6433824163820.4460254896660.01342104240620.3848979957480.05179801756260.5305311320030.209514550910.2737663708470.2119404576970.3267138748674.3085270713e-050.2668026485230.950126461520.4178659451730.5449097258710.6108014142290.05028117866580.1216247097020.506296731190.597427111060.2741210112710.0291515469950.8806728915080.9116678760680.09048386956960.5993091118760.6881648566310.05761313941230.08460972638960.3333169565780.5905745427370.9286697067210.1054244080560.3893761632950.7546462486390.7898283519040.0101459083460.5595522839060.4810305452110.3036887693060.990785722650.6153704641060.8357255270580.4597647094290.6324197465960.8442618921470.6710212839820.1468769365950.180227767670.9110606152380.6446608404840.9124711176990.5534636683320.7680968276070.04384287948450.3278122183370.9216822313160.5819012738550.721112072030.6171712762250.759219224015

Explicit Locators

For the ultimate flexibility in positioning tick locations and labels, you can use the toyplot.locator.Explicit locator. With it, you can specify an explicit set of labels, and a set of \([0, N)\) integer locations will be created to match. This is particularly useful if you are working with categorical data:

fruits = ["Apples", "Oranges", "Kiwi", "Miracle Fruit", "Durian"]
counts = [452, 347, 67, 21, 5]

canvas, axes, mark = toyplot.bars(counts, width=400, height=300)
axes.x.ticks.locator = toyplot.locator.Explicit(labels=fruits)
ApplesOrangesKiwiMiracle FruitDurian0100200300400

Note that in the above example the implicit \([0, N)\) tick locations match the implicit \([0, N)\) X coordinates that are generated for each bar when you don’t supply any X coordinates of your own. This is by design!

You can also use Explicit locators with a list of tick locations, and a set of tick labels will be generated using a format string. For example:

x = numpy.linspace(0, 2 * numpy.pi)
y = numpy.sin(x)
locations=[0, numpy.pi/2, numpy.pi, 3*numpy.pi/2, 2*numpy.pi]

canvas, axes, mark = toyplot.plot(x, y, width=500, height=300)
axes.x.ticks.locator = toyplot.locator.Explicit(locations=locations, format="{:.2f}")
0.001.573.144.716.28-1.0-0.50.00.51.0

Finally, you can supply both locations and labels to an Explicit locator:

labels = ["0", u"\u03c0 / 2", u"\u03c0", u"3\u03c0 / 2", u"2\u03c0"]

canvas, axes, mark = toyplot.plot(x, y, width=500, height=300)
axes.x.ticks.locator = toyplot.locator.Explicit(locations=locations, labels=labels)
0π / 2π3π / 2-1.0-0.50.00.51.0

Timestamp Locators

Toyplot includes the toyplot.locator.Timestamp locator which can be used to provide human-consumable date-time labels when your data’s domain is timestamps (seconds since the Unix epoch, i.e. midnight, January 1st, 1970, UTC). As an example, let’s load some real-world data containing date-time information:

import toyplot.data
data = toyplot.data.read_csv("commute-obd.csv")
data[:6]
DatetimeNameValueUnits
2014-05-01T14:08:53.587607ZStatus Since DTC Cleared0011110100110
2014-05-01T14:08:53.656972ZFuel System Status0000
2014-05-01T14:08:53.726403ZCalculated Load Value0.0%
2014-05-01T14:08:53.734393ZCoolant Temperature13C
2014-05-01T14:08:53.804349ZShort Term Fuel Trim0.0%
2014-05-01T14:08:53.873862ZLong Term Fuel Trim-3.125%

Our first step will be to convert the string datetimes from the file into true numeric timestamps. Note that for this example we’re using Arrow, a library that improves upon the builtin datetime functionality in Python. Note that Arrow is used in the timestamp locator implementation, so it must already be installed for the following examples to work:

import arrow
timestamps = numpy.array([arrow.get(datetime).timestamp for datetime in data["Datetime"]])

Now, we can plot the data using the timestamps as our independent variable:

observations = numpy.logical_and(data["Name"] == "Vehicle Speed", data["Value"] != "NODATA")
x = timestamps[observations]
y = data["Value"][observations]
canvas, axes, mark = toyplot.plot(
    x, y, label="Vehicle Speed", xlabel="Time", ylabel="km/h",
    width=600, height=300)
1398953000139895400013989550001398956000Time04080120km/hVehicle Speed

As you would expect, the timestamps make very unfriendly tick labels. Let’s use the timestamp locator instead:

canvas, axes, mark = toyplot.plot(
    x, y, label="Vehicle Speed", xlabel="Time", ylabel="km/h",
    width=600, height=300)
axes.x.ticks.show = True
axes.x.ticks.locator = toyplot.locator.Timestamp()
5/1 14:105/1 14:155/1 14:205/1 14:255/1 14:305/1 14:355/1 14:405/1 14:455/1 14:50Time04080120km/hVehicle Speed

By default, the timestamp locator chooses a “good” time interval based on the data domain - for this data, it chose to create ticks at five minute intervals. In addition, the locator also chooses a default format based on the interval - in this case, month/day hour:minute. This is a significant improvement over raw timestamps, but before we continue, we need to address timezone issues.

As alluded to above, in Toyplot all timestamps must always be UTC timestamps, without exception ... that is to say that the numeric values to be displayed by the timestamp locator must be the number of seconds since Midnight, January 1st, 1970, UTC time. Our current example data already contained UTC datetimes (note the “Z” timezone in the data file), so no special conversion was necessary. If for some reason you’re working with datetimes that aren’t UTC, you’ll need to take their timezone into consideration when converting them to timestamps for display by Toyplot ... and as an aside: you need to run, not walk to anyone collecting data using local timestamps, and make them stop!

Since all Toyplot timestamps are UTC, the times displayed by the timestamp locator are also UTC by default. If you prefer to display times using a specific timezone, you can specify it when creating the locator.

An Important Note on Timezone Names

The arrow library (and thus Toyplot) relies on the underlying operating system for its timezone information. The following examples use “US/Mountain” to identify a timezone, and should work on most posix-like systems including Linux and OSX. Unfortunately, Windows operating systems use a different naming scheme; if you are using Windows, you will need to substitute a different name, such as “US Mountain Standard Time”.

canvas, axes, mark = toyplot.plot(
    x, y, label="Vehicle Speed", xlabel="Time (US/Mountain)", ylabel="km/h",
    width=600, height=300)
axes.x.ticks.show = True
axes.x.ticks.locator = toyplot.locator.Timestamp(timezone="US/Mountain")
5/1 08:105/1 08:155/1 08:205/1 08:255/1 08:305/1 08:355/1 08:405/1 08:455/1 08:50Time (US/Mountain)04080120km/hVehicle Speed

Note that the hour in this data changed from 14:00 to 8:00, which makes more sense, since this data came from a morning commute. You could also specify a timezone of “utc” (the default) to explicitly document in the code that no timezone conversion is taking place. Finally, you may use “local” to automatically display the data using whichever timezone is local to the host running the code ... but be careful with this option, since it means that the the content of a figure could change based on where your laptop was when you generated it!

With timezones out of the way, let’s focus on the labels. The current set is a little crowded, so let’s look at different ways to clean things up. First, we can use the count attribute to request that the locator choose an interval that produces a specific number of ticks:

canvas, axes, mark = toyplot.plot(
    x, y, label="Vehicle Speed", xlabel="Time (US/Mountain)", ylabel="km/h",
    width=600, height=300)
axes.x.ticks.show = True
axes.x.ticks.locator = toyplot.locator.Timestamp(timezone="US/Mountain", count=5)
5/1 08:105/1 08:205/1 08:305/1 08:405/1 08:50Time (US/Mountain)04080120km/hVehicle Speed

Note that in most cases the locator won’t produce the exact number of ticks requested (we got lucky in this case), it will choose an interval that produces the closest match.

Alternatively, we might choose to accept the default tick count and alter the tick format, to save space:

canvas, axes, mark = toyplot.plot(
    x, y, label="Vehicle Speed", xlabel="Time (US/Mountain)", ylabel="km/h",
    width=600, height=300)
axes.x.ticks.show = True
axes.x.ticks.locator = toyplot.locator.Timestamp(
    timezone="US/Mountain", format="{0:HH}:{0:mm}")
08:1008:1508:2008:2508:3008:3508:4008:4508:50Time (US/Mountain)04080120km/hVehicle Speed

The individual tick values are passed to the format function as arrow.arrow.Arrow objects, so you can use any of the arrow attributes and formatting tokens in the format string, as we’ve done here.

Or, we might force a specific interval if it had special meaning for our domain, such as the number of seven-minute workouts we could have completed during our commute:

canvas, axes, mark = toyplot.plot(
    x, y, label="Vehicle Speed", xlabel="Time (US/Mountain)", ylabel="km/h",
    width=600, height=300)
axes.x.ticks.show = True
axes.x.ticks.locator = toyplot.locator.Timestamp(
    timezone="US/Mountain", interval=(7, "minutes"))
5/1 08:145/1 08:215/1 08:285/1 08:355/1 08:425/1 08:49Time (US/Mountain)04080120km/hVehicle Speed

Toyplot supports common intervals from seconds to millennia.

Finally, we might go in the opposite direction and show more detail in the timestamps. This is often a case where you’ll want to adjust the orientation of the labels so they don’t overlap (note in the following example that we had to make the canvas larger and position the axes manually on the canvas to make room for the angled labels - and we manually placed the x axis label to avoid overlap):

canvas = toyplot.Canvas(width=600, height=350)
axes = canvas.cartesian(bounds=(80, -80, 50, -120), label="Vehicle Speed", ylabel="km/h")
axes.plot(x, y)
axes.x.ticks.show = True
axes.x.ticks.locator = toyplot.locator.Timestamp(
    timezone="US/Mountain", format="{0:MMMM} {0:d}, {0:YYYY} {0:h}:{0:mm} {0:a}")
axes.x.ticks.labels.angle = 30
canvas.text(300, 320, "Time (US/Mountain)", style={"font-weight":"bold"});
May 4, 2014 8:10 amMay 4, 2014 8:15 amMay 4, 2014 8:20 amMay 4, 2014 8:25 amMay 4, 2014 8:30 amMay 4, 2014 8:35 amMay 4, 2014 8:40 amMay 4, 2014 8:45 amMay 4, 2014 8:50 am04080120km/hVehicle SpeedTime (US/Mountain)