Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TheAlgorithms/Python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: thedvlprguy/Python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 15 commits
  • 22 files changed
  • 2 contributors

Commits on Oct 22, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5b6a3da View commit details
  2. Merge pull request #1 from ascendantaditya/ascendantaditya-patch-1

    data-structures added with practice questions
    thedvlprguy authored Oct 22, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6cfccd0 View commit details
  3. Data Visualisation

    thedvlprguy authored Oct 22, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    552036b View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    aa92fda View commit details
  5. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0dbccae View commit details
  6. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    28828d6 View commit details
  7. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a9071e4 View commit details
  8. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    515388b View commit details
  9. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    74806da View commit details
  10. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5d565bf View commit details
  11. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    603d052 View commit details
  12. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    960c643 View commit details
  13. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f189d98 View commit details
  14. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bdf4ae1 View commit details
  15. Copy the full SHA
    935db1e View commit details
42 changes: 42 additions & 0 deletions Data Visualisation/Bar Chart/BarChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import plotly.graph_objects as go
import numpy as np

np.random.seed(42)

# declaring size of arr
size = 7

x = [f"Product {i}" for i in range(size)]
y = np.random.randint(low=0, high=100, size=size)

# creating the Bar Chart
fig = go.Figure(
go.Bar(
x=x,
y=y,
text=y,
textposition="outside",
marker_color="indianred",
hovertemplate="%{x} : %{y} <extra></extra>",
showlegend=False,
)
)

# Modifying the tickangle of the xaxis, and adjusting width and height of the image
fig.layout.template = "plotly_dark"
# Hiding y-axis labels
layout_yaxis_visible = False
layout_yaxis_showticklabels = False
fig.update_layout(
xaxis_title="X Axis Title",
yaxis_title="Y Axis Title",
xaxis_tickangle=-45,
autosize=False,
width=600,
height=600,
margin=dict(l=50, r=50, b=100, t=100, pad=4),
)
# Removing the background grid and the Y-axis labels
fig.update_yaxes(showgrid=False, showticklabels=False)

fig.show()
43 changes: 43 additions & 0 deletions Data Visualisation/Bubble Chart/BubbleChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import plotly.graph_objects as go
import numpy as np

np.random.seed(1)

# declaring size of arr
size = 10
size_arr = np.random.randint(low=50, high=600, size=size)

x = np.random.randint(low=0, high=30, size=size)
y = np.random.randint(low=0, high=20, size=size)

fig = go.Figure(
data=[
go.Scatter(
x=x,
y=y,
mode="markers",
marker=dict(
size=size_arr,
sizemode="area",
sizeref=2.0 * max(size_arr) / (40.0**2),
sizemin=4,
),
hovertemplate=" x : %{x} <br> y : %{y} <br>",
)
]
)

# Adjusting width and height of the image
fig.layout.template = "plotly_dark"
fig.update_layout(
title="Bubble Chart",
xaxis_title="X Axis Title",
yaxis_title="Y Axis Title",
autosize=False,
width=600,
height=600,
margin=dict(l=50, r=50, b=100, t=100, pad=4),
)


fig.show()
46 changes: 46 additions & 0 deletions Data Visualisation/Contour Plots/ContourPlots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import plotly.graph_objects as go
import numpy as np

# X , Y , Z cordinates
x_cord = np.arange(0, 50, 2)
y_cord = np.arange(0, 50, 2)
z_function = np.sin((x_cord + y_cord) / 2)

fig = go.Figure(
data=go.Contour(
x=x_cord,
y=y_cord,
z=z_function,
colorscale="darkmint",
contours=dict(
showlabels=False, # show labels on contours
labelfont=dict( # label font properties
size=12,
color="white",
),
),
colorbar=dict(
thickness=25,
thicknessmode="pixels",
len=1.0,
lenmode="fraction",
outlinewidth=0,
title="Title",
titleside="right",
titlefont=dict(size=14, family="Arial, sans-serif"),
),
)
)

fig.update_layout(
title="Contour Plot",
xaxis_title="X Axis Title",
yaxis_title="Y Axis Title",
autosize=False,
width=900,
height=600,
margin=dict(l=50, r=50, b=100, t=100, pad=4),
)

fig.layout.template = "plotly_dark"
fig.show()
41 changes: 41 additions & 0 deletions Data Visualisation/Funnel Chart/FunnelChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from plotly import graph_objects as go

fig = go.Figure()

fig.add_trace(
go.Funnel(
name="India",
y=["McDonalds", "Dominoz", "PizzaHut", "Subway", "MadOverDonuts", "Keventers"],
x=[150, 140, 40, 50, 40, 20],
textposition="inside",
textinfo="value+percent initial",
)
)

fig.add_trace(
go.Funnel(
name="Bangladesh",
orientation="h",
y=["McDonalds", "Dominoz", "PizzaHut", "Subway"],
x=[50, 60, 40, 30],
textposition="inside",
textinfo="value+percent previous",
)
)

fig.add_trace(
go.Funnel(
name="SriLanka",
orientation="h",
y=["McDonalds", "Dominoz", "PizzaHut", "Subway", "MadOverDonuts"],
x=[90, 70, 50, 30, 10],
textposition="outside",
textinfo="value+percent total",
)
)

fig.update_layout(
title="Funnel Chart for Food Sales in Asian Countries", showlegend=True
)
fig.layout.template = "plotly_dark"
fig.show()
30 changes: 30 additions & 0 deletions Data Visualisation/Heat Map/HeatMap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import plotly.express as px
import numpy as np

np.random.seed(42)

# declaring the size of an array
rows = 5
columns = 3

data = np.random.randint(low=0, high=50, size=(columns, rows))

fig = px.imshow(
data,
labels=dict(x="X Axis Title", y="Y Axis Title", color="Productivity"),
x=[f"Product {i}" for i in range(rows)],
y=[f"Type {i}" for i in range(columns)],
)

# Modifying the tickangle of the xaxis, and adjusting width and height of the image
fig.layout.template = "plotly_dark"
fig.update_xaxes(side="top")
fig.update_layout(
title="Heat Map ",
xaxis_tickangle=-45,
autosize=False,
width=600,
height=600,
margin=dict(l=50, r=50, b=100, t=100, pad=4),
)
fig.show()
23 changes: 23 additions & 0 deletions Data Visualisation/Histogram Plot/HistogramPlot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import plotly.express as px
import numpy as np

np.random.seed(0)

# declaring size of arr
size = 50

data = np.random.randint(low=0, high=150, size=size)
# create the bins
fig = px.histogram(x=data, labels={"x": "data", "y": "count"})

fig.layout.template = "plotly_dark"
fig.update_layout(
title="Histogram",
xaxis_title="X Axis Title",
yaxis_title="Y Axis Title",
autosize=False,
width=600,
height=600,
margin=dict(l=50, r=50, b=100, t=100, pad=4),
)
fig.show()
33 changes: 33 additions & 0 deletions Data Visualisation/Line Chart/LineChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import plotly.graph_objects as go
import numpy as np


def create_line_chart(x_data, y_data):
fig = go.Figure(data=go.Scatter(x=x_data, y=y_data))

# Modifying the tickangle of the xaxis, and adjusting width and height of the image
fig.layout.template = "plotly_dark"
fig.update_layout(
title="Line Chart",
xaxis_title="X Axis Title",
yaxis_title="Y Axis Title",
xaxis_tickangle=-45,
autosize=False,
width=600,
height=600,
margin=dict(l=50, r=50, b=100, t=100, pad=4),
)
fig.show()


if __name__ == "__main__":
np.random.seed(42)

# Generating sample data
x_data = np.arange(10)
y_data = x_data**2

try:
create_line_chart(x_data, y_data)
except Exception as e:
print("An error occurred:", str(e))
28 changes: 28 additions & 0 deletions Data Visualisation/Pie Chart/PieChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import plotly.graph_objects as go
import numpy as np

np.random.seed(42)

# declaring size of arr
size = 7

x = [f"Product {i}" for i in range(size)]
y = np.random.randint(low=0, high=100, size=size)

# creating a Pie Chart
fig = go.Figure(data=[go.Pie(labels=x, values=y)])

# Adjusting width and height of the image
fig.layout.template = "plotly_dark"
# To display labels with the percentage
fig.update_traces(textposition="inside", textinfo="percent+label")
fig.update_layout(
title="Pie Chart",
xaxis_title="X Axis Title",
yaxis_title="Y Axis Title",
autosize=False,
width=600,
height=600,
margin=dict(l=50, r=50, b=100, t=100, pad=4),
)
fig.show()
25 changes: 25 additions & 0 deletions Data Visualisation/Scatter Plot/ScatterPlot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import plotly.express as px
import numpy as np

np.random.seed(42)

# declaring size of arr
size = 100

x = np.random.randint(low=0, high=100, size=size)
y = np.random.randint(low=0, high=100, size=size)

fig = px.scatter(x=x, y=y)

# Adjusting width and height of the image
fig.layout.template = "plotly_dark"
fig.update_layout(
title="Scatter Plot",
xaxis_title="X Axis Title",
yaxis_title="Y Axis Title",
autosize=False,
width=600,
height=600,
margin=dict(l=50, r=50, b=100, t=100, pad=4),
)
fig.show()
44 changes: 44 additions & 0 deletions Data Visualisation/Ternary Plots/TernaryPlots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import plotly.express as px
import plotly.graph_objects as go

df = px.data.election()

fig = go.Figure(
go.Scatterternary(
{
"mode": "markers",
"a": df["Joly"],
"b": df["Coderre"],
"c": df["Bergeron"],
"marker": {
"color": "green",
"size": 14,
},
}
)
)
fig.update_layout(
{
"title": "Ternary Scatter Plot",
"ternary": {
"sum": 1,
"aaxis": {"title": "Joly", "min": 0.01, "linewidth": 2, "ticks": "outside"},
"baxis": {
"title": "Coderre",
"min": 0.01,
"linewidth": 2,
"ticks": "outside",
},
"caxis": {
"title": "Bergeron",
"min": 0.01,
"linewidth": 2,
"ticks": "outside",
},
},
"showlegend": False,
}
)

fig.layout.template = "plotly_dark"
fig.show()
26 changes: 26 additions & 0 deletions Data Visualisation/Waterfall Chart/WaterfallChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import plotly.express as px
import plotly.graph_objects as go

fig = go.Figure(
go.Waterfall(
name="20",
orientation="v",
measure=["relative", "relative", "relative", "relative", "relative", "total"],
x=["Exp1", "Exp2", "Exp3", "Exp4", "Exp5", "Exp6"],
textposition="outside",
text=["100", "50", "130", "200", "40", "Total"],
y=[100, +50, 130, 200, 40, 0],
connector={"line": {"color": "rgb(63, 63, 63)"}},
increasing={"marker": {"color": "green"}},
totals={"marker": {"color": "blue"}},
)
)

fig.update_layout(
title="Waterfall Chart",
showlegend=True,
xaxis_title="X Axis Title",
yaxis_title="Y Axis Title",
)
fig.layout.template = "plotly_dark"
fig.show()
Loading