Skip to content

Instantly share code, notes, and snippets.

<svg>
<circle cx=50 cy=50 r=20 stroke=darkblue fill=lightblue></circle>
</svg>
# topic_list = ["Accessibility", "Addiction", "Android Dev", "Artificial Intelligence",...]
# monthly_counts = {"Accessibility": 26, "Addiction": 71, "Android Dev": 132, "Artificial Intelligence": 101, ...}
html_string = ""
heading_list = []
for topic in topic_list:
# In Medium articles, the large headings are <h3> tags
string = "<h3>"+topic+"</h3>"
import plotly.graph_objects as go
fig2 = go.Figure(
data=[go.Pie(
labels=['Self-published','Top 10 Pubs.','Other Pubs.'],
values=[self_pub_count, top_ten_count, other_pubs_count], # these are counts generated from my data
marker=dict(
colors=['rgba(235, 141, 0, 0.75)', 'rgba(0, 45, 168, 0.5)', 'rgba(29, 122, 246,0.25)'],
line=dict(color='rgba(0, 45, 168, 1)', width=3) # style the pie sectors
),
pub_count, pubs = zip(*sorted(zip(pub_count, pubs), reverse=True))
pub_count_10 = list(pub_count)[0:10]
pub_names_10 = list(pubs)[0:10]
# pub_counts_10 = [131, 80, 32, 30, 26, 24, 18, 17, 16, 15]
# pub_names_10 = [['Cantors Paradise', 'Towards Data Science', 'MathAdam', 'Geek Culture', 'Nerd For Tech',
# 'Analytics Vidhya', 'Not Zero', 'The Breakthrough', 'DataDrivenInvestor', 'Math Simplified']
for a in sect.find_all('a'):
# i'm looking for an <a> tag in the <section> that starts with the string "&nbsp;in"
if (len(a.text) > 4 and a.text[0].isspace() and a.text[1:3] == "in"):
# The publication name is inside the <a> tag following the substring "&nbsp;in"
pub_name = a.text[4:]
if pub_name in pubs:
pub_count[pubs.index(pub_name)] += 1
else:
from bs4 import BeautifulSoup
with open("math-topic-page.html", encoding='utf-8') as f:
contents = f.read()
soup = BeautifulSoup(contents, 'lxml')
for sect in soup.find_all('section'):
...
import plotly.graph_objects as go
pub_counts_10.reverse() # reverse order so that largest bar is on top
pub_names_10.reverse() # (Plotly will graph the bottom bar first)
bar_chart = go.Figure(go.Bar(
x = pub_counts_10,
y = pub_names_10,
orientation='h', # horizontal bar chart
marker=dict(