The size of character parts from largest to smallest#

This notebook demonstrates analysing spoken part size of characters from a set of Shakespear plays with the help of SIA API.

@Hugh, some explaination about the purpose of doing this experiment

Firstly, a number of dependency modules are imported here.

  • requests: is used for sending requests to the SIA API.

  • matplotlib.pyplot: we use the Matplotlib to create the chart based on the results from the SIA API.

  • IPython.display: is used for rendering the results from the SIA API as HTML tables.

import requests
import matplotlib.pyplot as plt
from IPython.display import display, HTML

Next, we set up the API endpoint here. In this example, we use the Word Frequencies API.

request_url = "https://sia.ardc-hdcl-sia-iaw.cloud.edu.au/api/v1/word-frequencies"

In order to use the API, an API key is requried to authenticate the requests. The API key must be specified in a custom HTTP header X-API-KEY and sent along with every request.

You should use your own API keys for your own notebooks and always keep your keys confidential. Read more about how to create API keys in SIA.

api_key = "255446bcdde7ca9fe776258d09e8411bbb8d1cade2ebd6aba440f80f6817c3fd"

Then, we start to prepare the request data which we can send to the Word Frequencies API. In this example, we are going to use a text set containing 20 Shakespear plays which has been already uploaded in the SIA platform. Instead of passing the actual text contents to the API, we can tell the API to use one of the texts or text sets from SIA by specifying its ID.

The URL of a text/text set page from SIA Application indicates the ID of that text/text set. For example:

https://sia.ardc-hdcl-sia-iaw.cloud.edu.au/text-sets/86

In this case, the ID of the “20 Shakespear plays” text set is 86.

We will also pass serveral word frequecies options to the Word Frequencies API. These options are:

  • segmentByCharacter: We will segment these plays by characters.

  • blockMethod: We set the block method to 0(By text), which segments play characters in the scope of each text.

  • excludeWords: We are excluding some common punctuation marks from our analysis.

To view more details about options of Word Frequencies API, read the API documentation.

@Hugh: more explainations about these options may be specified here

request_data = {
    'textSet': 86,
    'option': {
        'segmentByCharacter': True,  #Segment by character
        'blockMethod' : 0,           #Segment by text
        'excludeWords': ["[","\\", "]", "_", "`", "!", "\"", "#", "%", "'", "(", ")", "+", ",", "-", "–", ".", "/", ":", ";", "{", "|", "}", "=", "~", "?" ],
    }
}

The SIA API accept JSON as the request data. Here we have constructed a Python dictionary object with the text set identifier and the word frequencies options. Next we are going to put all things together and use the Requests module to send the request to the SIA API.

# Make API request
response = requests.post(request_url, json=request_data, headers={"X-API-KEY": api_key}, timeout=1200)

We have specified the API endpoint, request data we defined earlier and the X-API-KEY HTTP header for the API request and received the response. Please note that the API call can take serveral minutes to finish based on the size of the text or text set. Therefore, we have set the request timeout to 1200 seconds.

Before we start unpacking the response data, we want to make sure the API call was successful by checking the HTTP response code. Read the API documentation for all error codes.

print(f"{response.status_code} {response.reason}")
assert response.status_code == 200
response_data = response.json()
200 OK

Now, we have the response data ready from Word Frequencies API. We firstly want to list all characters from these plays in a table and sort them from the highest spoken part size to the lowest. We are going to unpack the response data and extract the information related to our experiment. Read more about the response data of Word Frequencies API.

# Create a dictionary to hold word counts from all characters.
character_word_counts = {}
for block in response_data['blocks']:
    character_word_counts[block['name']] = block['size']

# Sort by word count.
character_word_counts = dict(sorted(character_word_counts.items(), key=lambda item: item[1], reverse=True)) # Python 3.7+

We have created a dictionary which uses character names as keys and spoken part size as values. Then we sorted the dictionary by the spoken part size from highest to lowest (Note that sorting dictionary is only supported in Python 3.7+. If you are using order versions of Python, you might need to use OrderedDict instead).

The next step is to generate the HTML markups based on the dictionary we created and render it.

# Table dispaly
html = '<div style="overflow: auto; max-height: 500px; margin-top: 40px;"><table border="1">'

# Add table header
html += '<tr><th>Rank</th><th>Character</th><th>Size</th></tr>'

# Add table rows
i = 0
for character_name, word_count in character_word_counts.items():
    i += 1
    html += f"<tr><td>{str(i)}</td><td>{character_name}</td><td>{str(word_count)}</td></tr>"

html += '</table></div>'

display(HTML(html))
RankCharacterSize
1Hamlet Q2~Hamlet, Prince of Denmark, son of the late King Hamlet and of Gertrude (1)11331
2Richard III Q1~Duke of Gloucester/Richard III (1)8479
3Othello Q1~Iago, Othello's ancient (1)8477
4Henry V F~King Henry V (1)8363
5Coriolanus~Caius Martius Coriolanus (1)6482
6Antony and Cleopatra~Antony (1)6055
7Othello Q1~Othello, A noble Moor in the service of the Ventian state (1)5974
81 Henry IV Q1~Sir John Falstaff (1)5604
9King Lear Q1~Lear; King of Britain (1)5488
10Macbeth~Macbeth (1)5484
11Julius Caesar~Brutus (1)5391
12Richard II Q1~King Richard (1)5376
13Winter's Tale~Leontes (1)4950
14Love's Labor's Lost Q1~Berowne, lord attending on the king (1)4859
15Antony and Cleopatra~Cleopatra (1)4778
16Romeo and Juliet Q2~Romeo, son to Montague (1)4777
17Tempest~Prospero (1)4733
18Merchant of Venice Q1~Portia, a rich heiress (1)4683
191 Henry IV Q1~Prince Henry; Son of Henry IV; later King Henry V (1)4424
20Coriolanus~Menenus Agrippa (1)4379
211 Henry IV Q1~Hotspur; Henry Percy; Son and heir of the Earl of Northumberland (1)4312
22Romeo and Juliet Q2~Juliet, daughter to Capulet (1)4279
23Hamlet Q2~King Claudius, King of Denmark, brother of the late King Hamlet (1)4116
24Much Ado About Nothing Q1~Benedicke (1)3776
25Julius Caesar~Cassius (1)3735
26King Lear Q1~Edgar; son of Gloster (1)2956
27Merchant of Venice Q1~Shylock, a rich Jew (1)2907
28Antony and Cleopatra~Caesar (1)2892
29Romeo and Juliet Q2~Frier Laurence, Franciscan (1)2755
30Twelfth Night~Sir Toby (1)2749
31Hamlet Q2~Polonius, a member of the Danish Privy Council (1)2675
32Much Ado About Nothing Q1~Leonato (1)2666
33Twelfth Night~Viola (1)2603
34Merchant of Venice Q1~Bassiano, Antonio's friend, suitor to Portia (1)2600
35Richard II Q1~Bullingbroke; later King Henry IV (1)2593
361 Henry IV Q1~King Henry IV (1)2576
37Richard III Q1~Duke of Buckingham (1)2575
38Julius Caesar~Mark Antony (1)2551
39King Lear Q1~Earl of Kent (1)2537
40Henry V F~Captain Fluellen; officer in Henry's army (1)2514
41King Lear Q1~Earl of Gloster (1)2505
42Othello Q1~Desdemona, Daughter to Brabantio and wife to Othello (1)2489
43Antony and Cleopatra~Enobarbus (1)2474
44Much Ado About Nothing Q1~Don Pedro; Prince (1)2473
45Winter's Tale~Paulina (1)2435
46Coriolanus~Volumnia (1)2425
47Much Ado About Nothing Q1~Beatrice (1)2374
48Twelfth Night~Feste (1)2361
49Winter's Tale~Autolicus (1)2348
50Twelfth Night~Olivia (1)2335
51King Lear Q1~Edmund; bastard son of Gloster (1)2324
52Love's Labor's Lost Q1~Don Adriano de Armado, a fantastical Spaniard (1)2294
53Romeo and Juliet Q2~Nurse to Juliet (1)2248
54Richard II Q1~Yorke (1)2204
55Love's Labor's Lost Q1~Princess of France (1)2192
56Romeo and Juliet Q2~Capulet, head of two houses at variance with each other (1)2157
57Comedy of Errors~Dromio of Syracuse (1)2153
58Twelfth Night~Malvolio (1)2132
59Winter's Tale~Camillo (1)2120
60Comedy of Errors~Antipholus of Syracuse (1)2118
61Romeo and Juliet Q2~Mercutio, kinsman to the Prince, and friend to Romeo (1)2094
62Love's Labor's Lost Q1~Ferdinand, king of Navarre (1)2079
63Coriolanus~Tullius Auffidus (1)2058
64Hamlet Q2~Horatio, a poor scholar, friend and confidant of Hamlet (1)2038
65Comedy of Errors~Adriana (1)2029
66Coriolanus~Annius Cominus (1)1975
67Much Ado About Nothing Q1~Claudio (1)1974
68Winter's Tale~Poloxenes (1)1972
69Midsummer Night's Dream Q1~Bottom (1)1969
70Richard III Q1~Queen Margaret, wife of Henry VI (1)1940
71Coriolanus~Sicinius Velutus (1)1895
72Othello Q1~Cassio, Othello's lieutenant (1)1855
73Midsummer Night's Dream Q1~Helena (1)1824
74Macbeth~Lady Macbeth (1)1805
75Comedy of Errors~Antipholus of Ephesus (1)1763
76Midsummer Night's Dream Q1~Theseus (1)1740
77Midsummer Night's Dream Q1~Oberon (1)1689
78Henry V F~Chorus (1)1674
79Henry V F~Archbishop of Canterbury (1)1658
80Richard III Q1~Queen Elizabeth Woodville, wife of Edward IV, mother of the 2 Princes (1)1636
81Twelfth Night~Orsino (1)1628
82Winter's Tale~clown (1)1621
83Winter's Tale~Hermione (1)1601
84Coriolanus~Brutus (1)1582
85Othello Q1~Emilia, Wife to Iago (1)1567
86King Lear Q1~Foole (1)1549
87Love's Labor's Lost Q1~Costard, a clown (1)1544
88Love's Labor's Lost Q1~Boyet, lord attending on the princess of France (1)1532
89Macbeth~Malcolm (1)1525
90Richard II Q1~Gaunt (1)1523
91Much Ado About Nothing Q1~Dogberry; Constable; Andrew; Kemp. (1)1522
92Twelfth Night~Maria (1)1472
93Merchant of Venice Q1~Launcelot Gobbo, the clown, servant to Shylock (1)1465
94Merchant of Venice Q1~Antonio, a merchant of Venice (1)1444
951 Henry IV Q1~Earl of Worcester (1)1430
96Hamlet Q2~Laertes, Polonius's son (1)1423
97Winter's Tale~Florizell (1)1399
98Love's Labor's Lost Q1~Rosaline, lady attending on the princess (1)1391
99Comedy of Errors~Dromio of Ephesus (1)1388
100Merchant of Venice Q1~Gratiano, friend to Antonio and Bassiano (1)1378
101Midsummer Night's Dream Q1~Robin Goodfellow/Puck (1)1376
102King Lear Q1~Regan; daughter to Lear (1)1366
103King Lear Q1~Gonorill; daughter to Lear (1)1363
104Tempest~Caliban (1)1354
105Merchant of Venice Q1~Lorenzo, in love with Jessica (1)1340
106Love's Labor's Lost Q1~Holofernes, a schoolmaster (1)1303
107Midsummer Night's Dream Q1~Demetrius (1)1291
108Midsummer Night's Dream Q1~Hermia (1)1290
109Richard III Q1~George, Duke of Clarence (1)1247
110Tempest~Stephano (1)1236
111Twelfth Night~Sir Andrew Aguecheek (1)1193
112Tempest~Gonzalo (1)1189
113Hamlet Q2~Ophelia, Polonius's daughter (1)1182
114Richard III Q1~Lady Anne Neville/wife of Edward, Prince of Wales/later Duchess of Gloucester (1)1171
115Macbeth~MacDuff (1)1169
116Richard III Q1~Lord Hastings (1)1156
117Romeo and Juliet Q2~Benvolio, nephew to Montague, and friend to Romeo (1)1156
118Comedy of Errors~Aegeon, merchant of Syracuse (1)1152
119Tempest~Aerial (1)1151
120Julius Caesar~Julius Caesar (1)1146
121Henry V F~Pistol (1)1126
122Midsummer Night's Dream Q1~Lysander (1)1122
123Love's Labor's Lost Q1~Moth, page to Armado (1)1114
124Midsummer Night's Dream Q1~Titania (1)1094
125Winter's Tale~Shepherd (1)1090
126Julius Caesar~Casca (1)1079
127Richard II Q1~Mowbray (1)1066
128Richard III Q1~Cecily Neville, Duchess of York, mother of Edward IV, Clarence, Richard III (1)1048
129Hamlet Q2~Queen Gertrad, Queen of Denmark, widow of the late King Hamlet and now the wife of his brother Claudius (1)1043
130Midsummer Night's Dream Q1~Quince (1)1033
131Tempest~Miranda (1)1022
132Richard II Q1~Northumberland (1)1020
133Twelfth Night~Sebastian (1)1013
134Tempest~Antonio (1)1003
135Much Ado About Nothing Q1~Borachio (1)999
136Richard III Q1~Earl of Richmond (1)996
137Tempest~Ferninand (1)995
138Much Ado About Nothing Q1~Hero (1)990
139Othello Q1~Brabantio, A senator of Venice (1)975
140Coriolanus~STAGE (1)973
141Henry V F~Duke of Exeter; uncle to Henry (1)966
142King Lear Q1~Duke of Albany (1)942
143Henry V F~Charles Delabreth; Constable of France (1)924
144Richard II Q1~Queen (1)924
145Antony and Cleopatra~Pompey (1)917
146Macbeth~Ross (1)913
147Henry V F~Louis the Dauphin (1)909
148Winter's Tale~Perdita (1)907
149Romeo and Juliet Q2~Lady Capulet, wife to Capulet (1)904
150Much Ado About Nothing Q1~John; Bastard (1)903
151Merchant of Venice Q1~Salerio, friend to Antonio and Bassiano (1)855
152King Lear Q1~Cordelia; daughter to Lear (1)835
153Tempest~Trinculo (1)833
154Richard III Q1~Lord Stanley, Earl of Derby (1)821
155Merchant of Venice Q1~Prince of Morocco, suitor to Portia (1)809
156Twelfth Night~Antonio (1)806
157Winter's Tale~Antigonus (1)796
158Antony and Cleopatra~STAGE (1)795
159Macbeth~Banquo (1)777
160Comedy of Errors~Luciana (1)770
161Twelfth Night~Fabian (1)763
162Tempest~King Alonso (1)752
163Richard II Q1~Duchess of York (1)741
164King Lear Q1~Duke of Cornwell (1)731
165Julius Caesar~Portia (1)726
166Hamlet Q2~Clowne 1, a grave-digger (1)719
167Tempest~Sebastian (1)715
168Othello Q1~Roderigo, A Venetian gentleman (1)708
169Hamlet Q2~First Player, leader of the troupe, enacts the role of a king (1)705
170Henry V F~King Charles VI of France (1)703
171Merchant of Venice Q1~Nerissa, Portia's maid-in-waiting (1)699
172Comedy of Errors~Solinus Duke of Ephesus (1)696
173Richard II Q1~Duke Aumerle (1)694
174Hamlet Q2~Ghost, of Hamlet's dead father (1)681
175Merchant of Venice Q1~Jessica, daughter to Shylock (1)667
176Coriolanus~1st Citizen (1)666
177King Lear Q1~Gentleman (1)658
178Comedy of Errors~Angelo (1)641
179Henry V F~Michael Williams; soldier in Henry's army (1)629
180Henry V F~Boy (1)626
1811 Henry IV Q1~Owen Glendower (1)618
182Much Ado About Nothing Q1~Friar Francis (1)595
183Winter's Tale~3 gentleman (1)595
184Romeo and Juliet Q2~Escalus, Prince of Verona (1)592
185Richard III Q1~STAGE (1)582
186Julius Caesar~Plebians (1)580
187Merchant of Venice Q1~Salanio, friend to Antonio and Bassiano (1)574
188Comedy of Errors~Gaoler/First Merchant/SecondMerchant (1)569
189Antony and Cleopatra~Charmian (1)562
190Merchant of Venice Q1~Duke of Venice (1)559
191Much Ado About Nothing Q1~Margaret (1)558
1921 Henry IV Q1~Edward Poins (1)556
193Love's Labor's Lost Q1~Dumain, lord attending on the king (1)555
194Comedy of Errors~Abbess Aemilia (1)554
195Macbeth~STAGE (1)554
196Hamlet Q2~STAGE (1)552
197Hamlet Q2~Rosencraus, courtier, old school fellow of Hamlet (1)546
198Romeo and Juliet Q2~Paris, a young nobleman, kinsman to the Prince (1)539
1991 Henry IV Q1~STAGE (1)535
200Othello Q1~Lodouico, Kinsman to Brabantio (1)534
201Love's Labor's Lost Q1~Longaville, lord attending on the king (1)523
202Love's Labor's Lost Q1~Sir Nathaniel, a curate (1)523
203Winter's Tale~servant (1)521
204Henry V F~Captain Gower; officer in Henry's army (1)512
205Henry V F~Duke of Burgundy (1)512
206Macbeth~Lennox (1)511
207Richard III Q1~King Edward IV (1)507
208King Lear Q1~Oswald; stewerd to Gonorill (1)505
209Merchant of Venice Q1~Prince of Arragon, suitor to Portia (1)500
210Richard III Q1~Sir William Catesby (1)492
211Othello Q1~Duke Of Venice (1)489
212Coriolanus~3rd Citizen (1)486
213Richard II Q1~Carl (1)486
214Antony and Cleopatra~Messenger (1)479
215Macbeth~King Duncan (1)474
216Richard III Q1~Second Executioner (1)467
2171 Henry IV Q1~Sir Richard Vernon (1)464
218Tempest~STAGE (1)457
219Richard II Q1~Duchess of Gloucester (1)456
220Othello Q1~STAGE (1)452
2211 Henry IV Q1~Edmund Mortimer; Earl of March (1)446
222Henry V F~Princess Katherine; daughter to Charles and Isabel (1)444
223Henry V F~STAGE (1)438
2241 Henry IV Q1~Lady Percy; Wife to Hotspur; Sister to Mortimer (1)423
225Much Ado About Nothing Q1~Leonato's Brother Anthony; Old Man (1)421
226Richard III Q1~First Executioner (1)421
227Julius Caesar~STAGE (1)420
228Hamlet Q2~Marcellus, a soldier (1)417
229Richard II Q1~Gardeners (1)415
230Winter's Tale~1 Lord (1)415
2311 Henry IV Q1~Hostess Quickly; Hostess of a tavern in Eastcheap (1)412
232Love's Labor's Lost Q1~Katharine, lady attending on the princess (1)409
233Othello Q1~Montanio, Othello's predecessor in the government of Cyprus (1)408
234Coriolanus~3rd Servingman (1)404
235Antony and Cleopatra~Lepidus (1)400
236Henry V F~Montjoy; a French Herald (1)400
237King Lear Q1~STAGE (1)394
238Romeo and Juliet Q2~STAGE (1)393
239Henry V F~Nym (1)392
240Coriolanus~Titus Lartius (1)390
241Midsummer Night's Dream Q1~Flute (1)387
242Much Ado About Nothing Q1~Vrsula (1)368
243Henry V F~Hostess; Pistol's wife; foremerly known as Mrs Quickly (1)365
244Hamlet Q2~Osric the Courtier (1)360
245Macbeth~witch 1 (1)359
246Tempest~Boatswain (1)355
247Much Ado About Nothing Q1~STAGE (1)354
248Coriolanus~Valeria (1)353
249Richard III Q1~Edward young Prince of Wales (1)349
2501 Henry IV Q1~Archibald; Earl of Douglas (1)346
251Antony and Cleopatra~Eros (1)343
252Antony and Cleopatra~Menas (1)340
253Richard III Q1~Richard Duke of York (1)334
254Julius Caesar~Octavius (1)329
255Richard III Q1~Lord Rivers (1)328
256Antony and Cleopatra~Dolabella (1)326
257Macbeth~Doctor (1)325
258Julius Caesar~Decius (1)324
2591 Henry IV Q1~Gadshill (1)323
260Henry V F~Duke of Orleans (1)319
261Coriolanus~combined voice (1)317
262Romeo and Juliet Q2~Montague, head of two houses at variance with each other (1)317
263Macbeth~Porter (1)316
264Romeo and Juliet Q2~Chief Serving-man (1)315
265Antony and Cleopatra~Agrippa (1)314
266Richard II Q1~STAGE (1)313
267Richard III Q1~Robert Brokenbury (1)308
2681 Henry IV Q1~Earl of Westmoreland (1)300
2691 Henry IV Q1~Sir Walter Blunt (1)299
270Midsummer Night's Dream Q1~Egeus (1)297
271Comedy of Errors~Courtezan (1)296
272Merchant of Venice Q1~STAGE (1)296
273Merchant of Venice Q1~Old Gobbo, father to Launcelot (1)295
274Romeo and Juliet Q2~Tybalt, nephew to Lady Capulet (1)295
275Tempest~Iris (1)295
276Comedy of Errors~STAGE (1)291
277Macbeth~Lady MacDuff (1)291
278Twelfth Night~STAGE (1)290
279Love's Labor's Lost Q1~Maria, lady attending on the princess (1)289
280Hamlet Q2~Guyldensterne, courtier, old school fellow of Hamlet (1)288
281Richard II Q1~Scroope (1)288
282Winter's Tale~Ladies/Mopsa/Dorcas (1)282
283Antony and Cleopatra~Alexas (1)281
284Richard II Q1~Bushie (1)276
285Richard II Q1~Persy (1)274
286Antony and Cleopatra~Scarus (1)272
287Richard III Q1~James Tyrrell (1)271
288Winter's Tale~Time/Chorus (1)267
289Midsummer Night's Dream Q1~STAGE (1)266
290Othello Q1~Bianca, Mistress to Cassio (1)265
291Macbeth~Hecate (1)264
292Romeo and Juliet Q2~Sampson, servant to Capulet (1)264
293Coriolanus~Messenger (1)263
294Coriolanus~2nd Servingman (1)262
2951 Henry IV Q1~Richard Scroop; Archbishop Scroop (1)261
296Julius Caesar~Messala (1)260
297Antony and Cleopatra~Clown (1)253
298Coriolanus~1st Senator (1)253
299Coriolanus~1st Watch (1)253
300Hamlet Q2~Second Player, enacts the role of a queen (1)252
301Love's Labor's Lost Q1~STAGE (1)252
302Midsummer Night's Dream Q1~Hippolita (1)252
303Much Ado About Nothing Q1~Conrade (1)252
304Tempest~song (1)250
305Antony and Cleopatra~Ventidius (1)247
306King Lear Q1~King of France (1)245
307Love's Labor's Lost Q1~Dull, a constable (1)245
308Richard II Q1~Green (1)243
309Coriolanus~1st Servingman (1)242
310Twelfth Night~Captain (1)241
311Winter's Tale~STAGE (1)237
312Macbeth~Captain (1)236
313Coriolanus~a Roman (1)235
314Antony and Cleopatra~Octavia (1)234
315Romeo and Juliet Q2~Peter, servant to Juliet's Nurse (1)234
3161 Henry IV Q1~Earl of NorthumberlandThomas Parcy; (1)233
317Julius Caesar~Titinius (1)233
318Julius Caesar~Marcellus (1)232
319Much Ado About Nothing Q1~Verges; Constable; Headborough; Cowley (1)232
320Coriolanus~Virgilia (1)231
321Richard III Q1~Third Citizen (1)230
322Much Ado About Nothing Q1~Messenger (1)229
323Henry V F~Bardolph (1)228
3241 Henry IV Q1~Lord Bardolph (1)223
325Antony and Cleopatra~Mecenas (1)223
326Winter's Tale~1 gentleman (1)222
327Romeo and Juliet Q2~Chorus (1)221
328Richard II Q1~Fitzs (1)218
329Antony and Cleopatra~Proculeius (1)216
330Hamlet Q2~Barnado, a soldier (1)212
331Antony and Cleopatra~Soothsayer (1)211
332Henry V F~Captain Macmorris (1)211
333Othello Q1~Clown, Servant to Othello (1)210
334Romeo and Juliet Q2~Balthasar, servant to Romeo (1)209
335Julius Caesar~Flavius (1)208
336Julius Caesar~Lucius (1)207
337Julius Caesar~Calpurnia (1)204
338Henry V F~Earl of Westmoreland (1)203
339Comedy of Errors~Balthazar (1)202
340Love's Labor's Lost Q1~Song (1)202
341Midsummer Night's Dream Q1~fairy/fairies (1)200
342Winter's Tale~officer (1)193
343Coriolanus~2nd officer (1)188
344Henry V F~Queen Isabel (1)188
345Richard III Q1~Richard Ratcliffe (1)188
346Hamlet Q2~Fortinbrasse, Prince of Norway (1)187
347Winter's Tale~Dion (1)187
348Antony and Cleopatra~Thidias (1)184
349Midsummer Night's Dream Q1~Philostrate (1)184
350Macbeth~gentlewoman (1)183
351Henry V F~Bishop of Ely (1)182
352Julius Caesar~Servant (1)181
353Macbeth~1 Murderer (1)180
354Richard II Q1~Exton (1)180
355Richard II Q1~Rosse (1)178
3561 Henry IV Q1~First Carrier (1)177
357Macbeth~Messenger (1)177
358Antony and Cleopatra~Soldier (1)176
359Much Ado About Nothing Q1~Song (1)175
360Winter's Tale~Archidamus (1)175
361Coriolanus~2nd Citizen (1)173
362Richard III Q1~Cardinal (1)172
363Henry V F~John Bates; soldier in Henry's army (1)168
364Julius Caesar~Lucilius (1)164
365Henry V F~Alice; a lady attending Katherine (1)162
366Coriolanus~a Volsce (1)161
367Macbeth~Lord (1)160
368Antony and Cleopatra~Iras (1)158
369Othello Q1~Gratiano, Brother to Brabantio (1)158
370Richard II Q1~Salisbury (1)156
371Antony and Cleopatra~Decretus (1)155
372Winter's Tale~Mamillius (1)155
373Midsummer Night's Dream Q1~Snout (1)153
374Julius Caesar~Pindarus (1)152
3751 Henry IV Q1~Chamberlain (1)150
376Richard III Q1~Clarence's son (1)150
377Hamlet Q2~Valtemand, Danish councillors, ambassador to Norway (1)149
378Macbeth~Seyward (1)147
379Richard II Q1~Lord Marshall (1)147
380Julius Caesar~Artemidarius (1)146
381Romeo and Juliet Q2~Gregory, servant to Capulet (1)146
382Julius Caesar~2 Citizen (1)145
383Macbeth~son of MacDuff (1)145
384Winter's Tale~Emilia (1)144
385Winter's Tale~Cleomines (1)144
386Antony and Cleopatra~Camidius (1)143
387Macbeth~combined voice (1)143
388Romeo and Juliet Q2~Frier John, Franciscan (1)143
3891 Henry IV Q1~Second Carrier (1)142
390Henry V F~Duke of Bourbon (1)141
391King Lear Q1~Doctor (1)141
392Coriolanus~2nd Messenger (1)137
393Macbeth~Angus (1)137
394Othello Q1~Second Gentleman (1)136
395Henry V F~Granpre (1)135
396Henry V F~First Ambassador (1)133
397Julius Caesar~Cinna the conspirator (1)133
398Richard III Q1~Lord Mayor of London (1)133
399Julius Caesar~Soothsayer (1)132
400Macbeth~witch 3 (1)132
401Midsummer Night's Dream Q1~Snug (1)129
402Antony and Cleopatra~Diomedes (1)127
403Macbeth~witch 2 (1)126
404Richard III Q1~Marquess of Dorset, Queen's son by first marriage (1)126
405Antony and Cleopatra~Philo (1)125
406Winter's Tale~2 gentleman (1)125
407Othello Q1~First Gentleman (1)124
408Richard III Q1~Multiple Speakers (1)123
409Antony and Cleopatra~Mardian (1)122
410Richard II Q1~Welsh Captain (1)122
411Julius Caesar~Metellus (1)121
412Richard III Q1~Scrivener (1)120
413King Lear Q1~Knight (1)118
414Antony and Cleopatra~Servant/1 Servant (1)117
415Coriolanus~1st Officer (1)117
416Richard III Q1~Messenger from Stanley to Hastings (1)117
417Othello Q1~First Senator, A senator of Venice (1)113
418Julius Caesar~Ligarius (1)112
419Othello Q1~Third Gentleman (1)112
420Merchant of Venice Q1~Servant (1)111
421Tempest~Ceres (1)111
422Hamlet Q2~Gentleman (1)110
423Hamlet Q2~Messenger (1)108
424Richard II Q1~O (1)108
425Antony and Cleopatra~Ambassador (1)107
426Coriolanus~2nd Senator (1)107
427Henry V F~Richard; Earl of Cambridge (1)107
428Much Ado About Nothing Q1~Sexton (1)106
429Much Ado About Nothing Q1~Balthazar (1)105
430Henry V F~French Soldier (1)104
431Julius Caesar~Cinna the poet (1)104
432Comedy of Errors~Pinch (1)103
433Love's Labor's Lost Q1~Jaquenetta, a country wench (1)102
434Richard II Q1~Will (1)102
435Twelfth Night~Valentine (1)102
436Antony and Cleopatra~2 Spldier (1)101
437Henry V F~Captain Jamy (1)101
438Twelfth Night~Officer 1 (1)101
439Richard II Q1~Bagot (1)99
440Twelfth Night~Song (1)99
441Merchant of Venice Q1~Tubal, a Jew, friend to Shylock (1)96
4421 Henry IV Q1~Peto (1)95
443Hamlet Q2~Clowne 2, his crony (1)95
444Antony and Cleopatra~Centerie (1)92
445Much Ado About Nothing Q1~ambo or either (1)92
446Richard II Q1~Groom (1)91
447Richard III Q1~Lord Richard Gray (1)91
448Antony and Cleopatra~1 Soldier (1)90
449Macbeth~Seyton (1)90
450Romeo and Juliet Q2~Serving-men 2 (1)90
451Coriolanus~1st Lord (1)89
452Hamlet Q2~Doctor/Priest (1)89
453Henry V F~Henry; Lord Scroop of Masham (1)89
454Richard III Q1~First Citizen (1)89
455Coriolanus~Lieutenant (1)88
456Macbeth~2 Murderer (1)87
457Othello Q1~Messenger (1)86
458Tempest~Juno (1)86
459Coriolanus~2nd Watch (1)85
460Much Ado About Nothing Q1~Watch 1 (1)85
4611 Henry IV Q1~Francis (1)84
462Antony and Cleopatra~Menecrates (1)84
463Hamlet Q2~Captain, in Fortinbras's army (1)84
464Macbeth~Old Man (1)84
465Coriolanus~Aedile (1)81
466Coriolanus~3rd Conspirator (1)81
467Henry V F~Sir Thomas Grey (1)81
468Winter's Tale~mariner (1)80
469Antony and Cleopatra~1 Guard (1)79
470Richard III Q1~Duke of Norfolke (1)79
471Tempest~Francisco (1)79
472Midsummer Night's Dream Q1~Starveling (1)78
473Romeo and Juliet Q2~Serving-men 3 (1)78
474Henry V F~John of Lancaster; Duke of Bedford; brother to Henry (1)77
475King Lear Q1~Seruant 1 (1)77
476Richard II Q1~Man (1)77
477Henry V F~Earl of Salisbury (1)76
478King Lear Q1~Curan; a courtier (1)75
479Macbeth~Cathnes (1)75
480Richard II Q1~Sur (1)75
481Richard II Q1~Abbot (1)72
482Winter's Tale~gaoler (1)72
483Julius Caesar~Clitus (1)71
484Macbeth~Menteith (1)71
485Richard III Q1~Second Citizen (1)71
486Richard III Q1~fourth messenger to Richard (1)71
487Romeo and Juliet Q2~Musician 1 (1)71
488Richard II Q1~Barkly (1)70
489Antony and Cleopatra~Romaine (1)67
490Hamlet Q2~Lord (1)67
491King Lear Q1~Duke of Burgundie (1)67
492Henry V F~Lord Rambures; French lord (1)66
4931 Henry IV Q1~Lord John of Lancaster; Son of Henry IV (1)64
494Comedy of Errors~Luce (1)64
495Tempest~Adrian (1)64
496Coriolanus~2nd Lord (1)62
497Julius Caesar~Cicero (1)62
498Julius Caesar~Trebonius (1)61
499Much Ado About Nothing Q1~Watch 2 (1)61
500Richard III Q1~Third Lord/Blunt (1)60
501Antony and Cleopatra~2 Servant (1)59
502Hamlet Q2~Reynaldo, Polonius's servant (1)59
5031 Henry IV Q1~Sheriff (1)58
504Coriolanus~1st Soldier (1)58
505Macbeth~Donalbain (1)58
506Romeo and Juliet Q2~Serving-men 1 (1)58
507Antony and Cleopatra~multiple speakers (1)57
508Julius Caesar~combined voice (1)57
509King Lear Q1~Herald (1)57
510Richard II Q1~Martiall (1)57
511Richard III Q1~Sir Christopher/pursuivant (1)57
512Twelfth Night~Priest (1)57
5131 Henry IV Q1~Messenger (1)56
514Coriolanus~1st Conspirator (1)56
515Hamlet Q2~Francisco, a soldier (1)56
516Henry V F~Govenor of Harfleur (1)56
517Julius Caesar~Poet (1)56
518Julius Caesar~Young Cato (1)54
519Merchant of Venice Q1~Stephano, servant to Portia (1)54
520Midsummer Night's Dream Q1~song (1)54
521Richard III Q1~Ghost of Henry VI (1)54
5221 Henry IV Q1~Sir Michael; Friend of Scroop's (1)53
523Henry V F~Sir Thomas Erpingham (1)53
524Richard III Q1~third messenger to Richard (1)53
525Romeo and Juliet Q2~An Apothecary (1)53
526Richard III Q1~Ghost of Prince Edward, son of Henry VI (1)52
527Romeo and Juliet Q2~Letter (1)52
528Julius Caesar~Strato (1)51
529Richard III Q1~Clarence's daughter (1)51
530Hamlet Q2~More than one speaker (1)50
531Macbeth~3 Murderer (1)50
532Richard II Q1~Herald 2 (1)48
533Richard II Q1~Herald (1)47
534Coriolanus~4th Citizen (1)45
535Macbeth~Young Seyward (1)44
536Richard II Q1~Another L (1)44
537Richard II Q1~Serving Man (1)43
538Richard II Q1~L Persy (1)43
539Coriolanus~3rd Senator (1)42
540Romeo and Juliet Q2~Musician 2 (1)42
541Antony and Cleopatra~Song/Boy (1)41
542Twelfth Night~Curio (1)41
543Coriolanus~Herald (1)40
544Hamlet Q2~Third Player, enacts the role of Lucianus, nephew of the king (1)40
545Hamlet Q2~Saylers (1)40
546Hamlet Q2~Embassadors (1)40
547King Lear Q1~Seruant 3 (1)40
548King Lear Q1~Old man; tenant to Gloster (1)40
549Coriolanus~2nd Conspirator (1)39
550Othello Q1~Second Senator, A senator of Venice (1)39
551Antony and Cleopatra~Egyptian (1)38
552King Lear Q1~Captain (1)38
553Richard III Q1~Boy telling Richard about Tyrell (1)38
554Richard II Q1~Keeper (1)37
555Henry V F~Messenger (1)36
556King Lear Q1~Seruant 2 (1)36
557Antony and Cleopatra~Demetrius (1)35
558Love's Labor's Lost Q1~Forester (1)35
5591 Henry IV Q1~Vintner (1)33
560Macbeth~apparition 3 (1)33
561Richard III Q1~first messenger to Richard (1)33
5621 Henry IV Q1~First Traveller (1)32
563Julius Caesar~Octavius' servant (1)32
564Midsummer Night's Dream Q1~Fairy1/Cobweb (1)32
565Richard II Q1~Lady (1)31
566Macbeth~Servant (1)29
567Antony and Cleopatra~Varrius (1)28
568Henry V F~Humphrey; Duke of Gloucester; brother to Henry (1)28
569Love's Labor's Lost Q1~Mercade, lord attending on the princess of France (1)28
570Romeo and Juliet Q2~Lady Montague, wife to Montague (1)28
571Julius Caesar~1 Soldier (1)27
572Richard III Q1~Bishop of Exeter (1)27
573Romeo and Juliet Q2~Multiple Speakers (1)27
574Antony and Cleopatra~Seleucus (1)26
575Othello Q1~Sailor (1)26
576Romeo and Juliet Q2~Horatio (1)26
577Love's Labor's Lost Q1 (1)25
578Othello Q1~First Officer (1)25
579Julius Caesar~Messenger (1)24
580Romeo and Juliet Q2~Abraham, servant to Montague (1)24
581Julius Caesar~Letter (1)23
582Macbeth~apparition 2 (1)23
583Othello Q1~First Musician (1)23
584Richard III Q1~second messenger to Richard (1)23
585Julius Caesar~Lepidus (1)22
586Antony and Cleopatra~Guardsman (1)21
587Julius Caesar~Varrus (1)21
588Richard III Q1~Pursuivant named Hastings (1)21
589Twelfth Night~Servant (1)21
590Coriolanus~Citizen (1)20
5911 Henry IV Q1~Servant (1)19
592Coriolanus~Young Martius (1)19
593Twelfth Night~Officer 2 (1)19
594Winter's Tale~combined voice (1)19
595Coriolanus~Romans (1)18
596Coriolanus~7th Citizen (1)18
597Julius Caesar~Volumnius (1)18
598Romeo and Juliet Q2~Capulet's Cousin (1)18
599Macbeth~Fleance (1)17
600Richard III Q1~Bishop of Ely (1)17
601Tempest~Ships Master (1)17
602Hamlet Q2~Fourth Player (1)16
603Much Ado About Nothing Q1~Lord (1)16
604Romeo and Juliet Q2~An Officer (1)16
605Julius Caesar~Dardanius (1)15
606Merchant of Venice Q1~Servant, of Antonio (1)15
607Romeo and Juliet Q2~Page to Paris (1)15
608Coriolanus~5th Citizen (1)14
609Henry V F~Duke of York; cousin to Henry, formerly Aumerle (1)14
610Richard III Q1~Ghost of Vaughan (1)14
611Coriolanus~gentlewoman (1)13
612Macbeth~apparition 1 (1)13
613Midsummer Night's Dream Q1~Fairy2/PeaseBlossom (1)13
614Richard III Q1~First Lord/Oxford (1)13
615Coriolanus~6th Citizen (1)12
616Coriolanus~3rd Lord (1)12
617Antony and Cleopatra~3 Soldier (1)11
618Coriolanus~1st Patrician (1)11
619Henry V F~Alexander Court; soldier in Henry's army (1)11
620Merchant of Venice Q1~Leonardo, servant to Bassiano (1)11
621Richard III Q1~Another (1)11
622Julius Caesar~Popilius (1)10
623Richard III Q1~Second Lord/Herbert (1)10
624Antony and Cleopatra~1 Messenger (1)9
625Antony and Cleopatra~1 Watch (1)9
626Richard III Q1~Gentleman accompanying hearse (1)9
6271 Henry IV Q1~Second Messenger (1)8
628Henry V F~Earl of Warwich (1)8
629Henry V F~Herald (1)8
630King Lear Q1~Messenger (1)8
631Merchant of Venice Q1 (1)8
632Othello Q1 (1)8
633Tempest~Mariner (1)8
634Winter's Tale~Song (1)8
635Hamlet Q2 (1)7
636Henry V F~Multiple Speakers (1)7
637Julius Caesar~2 Soldier (1)7
638Merchant of Venice Q1~Balthasar, servant to Portia (1)7
639Midsummer Night's Dream Q1~ambo or either (1)7
640Midsummer Night's Dream Q1~Fairy3/Mustardseed (1)7
641Romeo and Juliet Q2~Musician 3 (1)7
642Antony and Cleopatra~4 Soldier (1)6
643Antony and Cleopatra~2 Guard (1)6
644Coriolanus~Senator (1)6
645Julius Caesar~Publius (1)6
646Julius Caesar~Claudio (1)6
647Love's Labor's Lost Q1~First Lord (1)6
648Much Ado About Nothing Q1~Boy (1)6
649Othello Q1~All (1)6
650Antony and Cleopatra~2 Messenger (1)5
651Antony and Cleopatra~3 Messenger (1)5
652Antony and Cleopatra~3 Guard (1)5
653Merchant of Venice Q1~Ensemble (1)5
6541 Henry IV Q1~Carrier (1)4
655Antony and Cleopatra (1)4
656Coriolanus~2nd Patrician (1)4
657Coriolanus~Lords speaking together (1)4
658Julius Caesar~1 Citizen (1)4
659Macbeth~Soldier (1)4
660Midsummer Night's Dream Q1 (1)4
661Much Ado About Nothing Q1 (1)4
662Othello Q1~Voice off (1)4
663Richard III Q1~Servant carrying hearse (1)4
6641 Henry IV Q1~Second Travller (1)3
6651 Henry IV Q1~Ostler (1)2
666Antony and Cleopatra~Towrus (1)2
667Coriolanus~2nd Soldier (1)2
6681 Henry IV Q1~Thieves (1)1

Now we have created a 3-column table. Each cell in the “Character” column contains the play name and the character name from that play separated by tilde (~).

@Hugh: more insights about the table can be described here

Next, we are going to visualise these data in a scatter plot using the Matplotlib library. Note that the plot will only show the top 640 characters.

# Create the rank range from 1 to 640.
ranks = range(1, 641)

# Slice top 640 characters from the list. 
sizes = list(character_word_counts.values())[0:640]

# Scatterplot
plt.figure(figsize=(16, 6))
plt.scatter(ranks, sizes, c='blue')
plt.xticks(range(0, 701, 100))  # Set tick marks up to 700
plt.xlim([0, 700])  # Set x-axis limits up to 700
plt.ylim([0, 12000]) # Set x-axis limits up to 12000
plt.xlabel('Rank')
plt.ylabel('Size of Spoken Part')
plt.title('Size of Character Parts in 20 Shakespeare Plays')
plt.show()
../_images/ca4b5de3f469d862483f7a7199037cfc2169ba5695f1b98bb12cac0699d1b2ab.png

@Hugh: some insights about the chart