Skip to content

Instantly share code, notes, and snippets.

@bkamapantula
Created February 10, 2020 12:51
Show Gist options
  • Save bkamapantula/fdeb9993e5944edfa6dff08763775418 to your computer and use it in GitHub Desktop.
Save bkamapantula/fdeb9993e5944edfa6dff08763775418 to your computer and use it in GitHub Desktop.
Draw India sit-ins map
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import geopandas
import matplotlib.pyplot as plt
import matplotlib.image as image
# In[2]:
cols = ['Date', 'venue', 'Latitude', 'Longitude']
# In[7]:
df = pd.read_csv('sit-ins-8-feb.csv')[cols]
df['Date'] = pd.to_datetime(df['Date'])
venue_ignore = ['Tolichowki'] # ignored as the sit-in wasn't allowed to be organized
# df = df[!df['venue'].isin(venue_ignore)]
print(df.shape)
df = df.query("venue not in @venue_ignore")
print(df.shape)
# In[4]:
gdf = geopandas.GeoDataFrame(
df, geometry=geopandas.points_from_xy(df.Longitude, df.Latitude))
print(gdf.head())
gdf.dtypes
# ## Sit-in(s) map
# 15 dec, shaheen bagh | 28.5513373, 77.296996
#
# 28 dec, shanti bagh | 24.7931948, 84.9903235
#
# 11 jan, Sabji Bagh 25.6176855 85.1589544
#
# 12 jan, Mansoor Park/Roshan bagh 25.435545 81.8244194
#
# 14 jan, Manik Bagh 22.6952284 75.8550246
#
# 17 jan, Company Bagh 26.1195629 85.3910581
#
# 18 jan, Chand Bagh (Bhajanpura) 28.7034266 77.2650325
#
# 18 jan, Lalbagh 26.1554478 85.8927659
#
# 21 jan, Ghazi Bagh 22.3583144 74.7907577
#
# 21 jan, Vasant Bagh 16.847973 74.5610297
#
# 24 jan, Motibagh 26.1610992 75.7872919
#
# 25 jan, Tipu Bagh 16.2076287 77.3462705
#
# 28 jan, RaniBagh 25.7269664 86.5986509
#
# 31 jan, Gulzarbagh 24.8866859 85.5434572
#
# 1 feb, Sameedbagh 24.8866859 85.5434572
#
# In[6]:
plt.rcParams["figure.figsize"] = (10, 12)
india = geopandas.read_file('india.geojson')
# print(india.head(2))
# prototype map
# ax = india.plot(color='white', edgecolor='gray', alpha=0.4)
# gdf.plot(ax=ax, color='y')
# plt.axis('off')
# plt.title('Count of protests across India', fontsize=20)
# plt.text(75, 7, 'By @BehanBox', fontsize=16)
# plt.text(75, 4, 'Data curated by @bhanupriya_rao, map by @thoughtisdead. As of 8th Feb, 2020.', fontsize=12)
# plt.annotate('Shaheen Bagh', xy=(77, 28.5), xytext=(70, 28.5),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3")
# ) # 14 dec shaheen bagh | 28.5513373, 77.296996
# plt.annotate('Shanti Bagh', xy=(84.5, 24.5), xytext=(80.5, 23.5),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3")
# ) # 28 dec shanti bagh | 24.7931948, 84.9903235
# plt.annotate('Sabji Bagh', xy=(85, 25), xytext=(83.2, 28),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3,rad=0.5")
# ) # 11 jan Sabji Bagh 25.6176855 85.1589544
# plt.annotate('Mansoor Park/Roshan Bagh', xy=(81.8, 25.5), xytext=(79.5, 29),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3")
# ) # 12 jan Mansoor Park/Roshan bagh 25.435545 81.8244194
# plt.annotate('Manik Bagh', xy=(75.8, 22.6), xytext=(76.5, 21.8),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3")
# ) # 14 jan, Manik Bagh 22.6952284 75.8550246
# plt.annotate('Company Bagh', xy=(85.3, 26), xytext=(87.5, 27.5),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3")
# ) # 17 jan, Company Bagh 26.1195629 85.3910581
# plt.annotate('Chand Bagh (Bhajanpura)', xy=(77.2, 28.5), xytext=(73.8, 31),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3")
# ) # 18 jan, Chand Bagh (Bhajanpura) 28.7034266 77.2650325
# plt.annotate('Lalbagh', xy=(85.8, 26), xytext=(83, 22),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3,rad=0.3")
# ) # 18 jan, Lalbagh 26.1554478 85.8927659
# plt.annotate('Ghazi Bagh', xy=(74.7, 22.3), xytext=(72, 19.6),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3")
# ) # 21 jan, Ghazi Bagh 22.3583144 74.7907577
# plt.annotate('Vasant Bagh', xy=(74.5, 16.8), xytext=(72, 17.6),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3,rad=0.3")
# ) # 21 jan, Vasant Bagh 16.847973 74.5610297
# plt.annotate('Motibagh', xy=(75.7, 26.1), xytext=(72, 24.6),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3,rad=0.3")
# ) # 24 jan, Motibagh 26.1610992 75.7872919
# plt.annotate('Tipu Bagh', xy=(77.3, 16.19), xytext=(76.2, 14.5),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3")
# ) # 25 jan, Tipu Bagh 16.2076287 77.3462705
# plt.annotate('RaniBagh', xy=(86.5, 25.7), xytext=(88, 24.5),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3,rad=-0.3")
# ) # 28 jan, RaniBagh 25.7269664 86.5986509
# plt.annotate('Gulzarbagh, Sameedbagh', xy=(85.5, 24.8), xytext=(85.5, 21.2),
# arrowprops=dict(facecolor='black', arrowstyle="->",
# connectionstyle="arc3,rad=-0.3")
# ) # 31 jan, Gulzarbagh 24.8866859 85.5434572
# plt.show()
total = 0
# In[78]:
# shaheen bagh | 28.5513373, 77.296996
# shanti bagh | 24.7931948, 84.9903235
# ### Per day map
# In[79]:
ax = india.plot(color='white', edgecolor='gray', alpha=0.4)
# ctx.add_basemap(ax, url=ctx.providers.Stamen.TonerBackground)
credit_ppl = 'By @BehanBox. Data curated by @bhanupriya_rao, map by @thoughtisdead. As of 8th Feb, 2020.'
sitins_left = "Sit-in Dates in these places couldn't be determined: Khajrana (MP); \nSherghati, Bhadiya, Bara, Mangal Talab, Katihar, Araria, Quilaghat (BR); Asansol (WB);\nSangod Idgah, Masjid Gali Chawani (RJ); Hinganghat (MH)."
for d, m in gdf.groupby(['Date']):
m.plot(ax=ax, color='navy')
plt.axis('off')
total += len(m)
d = m['Date'].iloc[0].strftime('%d %B')
title = '{} - {} sit-in(s) | Total - {}'.format(d, len(m), total)
plt.title(title, fontsize=20)
print("...", d)
if(d == '14 December'):
plt.text(68, 3, sitins_left, fontsize=11)
plt.text(68, 1, credit_ppl, fontsize=10, style='italic')
plt.annotate('Shaheen Bagh', xy=(77, 28.5), xytext=(70, 28.5),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3")
)
if(d == '28 December'):
plt.annotate('Shanti Bagh', xy=(84.5, 24.5), xytext=(80.5, 23.5),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3")
)
if(d == '11 January'):
plt.annotate('Sabji Bagh', xy=(85, 25), xytext=(83.2, 28),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3,rad=0.5")
) # 11 jan Sabji Bagh 25.6176855 85.1589544
if(d == '12 January'):
plt.annotate('Mansoor Park/Roshan Bagh', xy=(81.8, 25.5), xytext=(79.5, 29),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3")
) # 12 jan Mansoor Park/Roshan bagh 25.435545 81.8244194
if(d == '14 January'):
plt.annotate('Manik Bagh', xy=(75.8, 22.6), xytext=(76.5, 21.8),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3")
) # 14 jan, Manik Bagh 22.6952284 75.8550246
if(d == '17 January'):
plt.annotate('Company Bagh', xy=(85.3, 26), xytext=(87.5, 27.5),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3")
) # 17 jan, Company Bagh 26.1195629 85.3910581
if(d == '18 January'):
plt.annotate('Chand Bagh (Bhajanpura)', xy=(77.2, 28.5), xytext=(73.8, 31),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3")
) # 18 jan, Chand Bagh (Bhajanpura) 28.7034266 77.2650325
plt.annotate('Lalbagh', xy=(85.8, 26), xytext=(83, 22),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3,rad=0.3")
) # 18 jan, Lalbagh 26.1554478 85.8927659
if(d == '21 January'):
plt.annotate('Ghazi Bagh', xy=(74.7, 22.3), xytext=(72, 19.6),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3")
) # 21 jan, Ghazi Bagh 22.3583144 74.7907577
plt.annotate('Vasant Bagh', xy=(74.5, 16.8), xytext=(72, 17.6),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3,rad=0.3")
) # 21 jan, Vasant Bagh 16.847973 74.5610297
if(d == '24 January'):
plt.annotate('Motibagh', xy=(75.7, 26.1), xytext=(72, 24.6),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3,rad=0.3")
) # 24 jan, Motibagh 26.1610992 75.7872919
if(d == '25 January'):
plt.annotate('Tipu Bagh', xy=(77.3, 16.19), xytext=(76.2, 14.5),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3")
) # 25 jan, Tipu Bagh 16.2076287 77.3462705
if(d == '28 January'):
plt.annotate('RaniBagh', xy=(86.5, 25.7), xytext=(88, 24.5),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3,rad=-0.3")
) # 28 jan, RaniBagh 25.7269664 86.5986509
if(d == '31 January'):
plt.annotate('Gulzarbagh', xy=(85.5, 24.8), xytext=(85.5, 21.2),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3,rad=-0.3")
) # 31 jan, Gulzarbagh 24.8866859 85.5434572
if(d == '1 February'):
plt.annotate('Sameedbagh', xy=(85.5, 24.8), xytext=(85.5, 21.2),
arrowprops=dict(facecolor='black', arrowstyle="->",
connectionstyle="arc3,rad=-0.3")
) # 31 jan, Gulzarbagh 24.8866859 85.5434572
plt.savefig(str(m['Date'].iloc[0]).split(' ')[0] + '.png', format='png', dpi=300)
# In[80]:
for d, m in gdf.groupby(['Date']):
# print(d, str(m['Date'].iloc[0]).split(' ')[0], m['Date'].iloc[0].strftime('%dth %B'), m.shape)
print(d, m, len(m))
# ## Video from images using ffmpeg
#
# ```bash
# cat *.png | ffmpeg -f image2pipe -framerate 1 -i - -c:v libx264 -vf format=yuv420p -r 25 sitins.mp4
# ```
@bkamapantula
Copy link
Author

2020-02-07

the final image in a series of 37 days of data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment