This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LinearAlgebra | |
using JuMP | |
using GLPK | |
using Plots | |
pyplot() | |
model = Model() | |
set_optimizer(model, GLPK.Optimizer) | |
#Define variables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
OlderNewer