Skip to content

Instantly share code, notes, and snippets.

View hbshrestha's full-sized avatar

Himalaya hbshrestha

  • Bonn, Germany
  • 11:34 (UTC +02:00)
View GitHub Profile
dropdowns = [] #Initialize as an empty list
i = 0 #Intialize a counter
#Iterate through df_dict
for key,value in df_dict.items():
#add a bar trace to the figure for each indicator
fig.add_trace(go.Bar(name=key,
x=value.iloc[:,0], #x is the squad name
y=value.iloc[:,1], #y is the value for each indicator
visible= (i==0), #Set only the indicator corresponding to i to be visible as default
fig.update_layout(
updatemenus=[
dict(
#Specify direction in which you want the dropdown menu to pop up
direction="down",
#(1.18,1) refers to the top right corner of the plot
x = 1.18,
y = 1,
#the list of buttons we created earlier
buttons = dropdowns)],
#Number of frames equivalent to number of rows
numOfFrames=df.shape[0]
top_clubs=["Atletico Madrid","Real Madrid","FC Barcelona"]
x_init = np.array([1])
initial_data = []
for club in top_clubs:
y_axis = np.array(df.loc[0, club])
initial_data.append(go.Scatter(x =x_init, y = y_axis,mode = "lines",name = club))
@hbshrestha
hbshrestha / world bank dataset
Last active September 18, 2021 18:11
world bank dataset
from pandas_datareader import wb
import pandas as pd
#Indicators: GDP, GDP per capita, access to electricity, population, CO2 emissions
indicators = ["NY.GDP.MKTP.CD", "NY.GDP.PCAP.CD", "EG.ELC.ACCS.ZS",
"SP.POP.TOTL", "EN.ATM.CO2E.KT"]
#ISO Code of countries: Australia, Bhutan, Germany, France, Indonesia, India, Japan,
#Korea, Netherlands, Nepal, Russia, South Africa
countries = ["AUS", "BTN", "DEU", "FRA", "IDN", "IND", "JPN",
from pyomo.environ import *
model = ConcreteModel()
#Define variables x and y
model.x = Var (domain = NonNegativeReals)
model.y = Var (domain = NonNegativeReals)
#Define objectives
model.obj = Objective (expr = 90 * model.x + 75 * model.y, sense = maximize)
plt.figure(figsize = (10,8))
plt.rcParams["font.size"] = 15
plt.axis([0, 50, 0, 50])
#Hours constraint of machine A
x = np.array([0,50]); y = 33 - 1.5*x
plt.plot(x, y, "red", label = "Machine A Hours Constraint")
plt.fill_between([0, 22], [33,0], color = "red", alpha = 0.05)
#Hours constraint of machine B
using LinearAlgebra
using JuMP
using GLPK
using Plots
pyplot()
model = Model()
set_optimizer(model, GLPK.Optimizer)
#Define variables
x=LinRange(0, 50, 100)
#Hours constraint for machine A
plot([x], [-1.5x .+ 33], label = "Machine A Constraint", color = "red")
plot!([0,22],[33,0], fillrange = 1, fillalpha = 0.05, fillcolor = "red", label = "")
#Optimal Product Strategy
scatter!([10],[18], marker = true,markercolor = "red", label = "", markersize = 7)
plot!([11,18],[19,25],arrow=true, color=:black,linewidth=2,label="")
annotate!(22, 27, text("Optimal Product Strategy",10))
@hbshrestha
hbshrestha / total population saarc region
Created December 24, 2021 17:23
Total population across SAARC in 1990 and 2020
plt.rcParams["figure.figsize"] = (12, 6)
plt.rcParams["font.size"] = 14
colors = ["red","green","gold","orange","blue","skyblue","maroon","grey"]
fig, ax = plt.subplots()
df_pop.T.plot.bar(stacked = True, ax = ax, color = colors)
ax.set_ylabel("Population")
ax.xaxis.set_ticklabels(ticklabels = [1990, 2020], rotation = 0)
for i in range(len(df_pop)):
@hbshrestha
hbshrestha / population distribution by gender in SAARC
Created December 24, 2021 17:26
population distribution by gender in SAARC
fig, ax = plt.subplots(figsize = (10, 8))
saarc.plot(color = "whitesmoke", edgecolor = "gray", ax = ax, alpha = 1)
ax.set_title("Population distribution in SAARC countries by gender in 2020", fontsize = 16, fontweight = "bold")
for index, row in saarc.iterrows():
centroid = row.geometry.centroid
mx, my = centroid.x, centroid.y