Skip to content

Data Visualisation #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Data Visualisation/Bar Chart/BarChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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()
Binary file added Data Visualisation/Bar Chart/barchart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Data Visualisation/Bubble Chart/BubbleChart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions Data Visualisation/Bubble Chart/BubbleChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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.*max(size_arr)/(40.**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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions Data Visualisation/Contour Plots/ContourPlots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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()
Binary file added Data Visualisation/Funnel Chart/FunnelChart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Data Visualisation/Funnel Chart/FunnelChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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()
Binary file added Data Visualisation/Heat Map/HeatMap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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))
Binary file added Data Visualisation/Pie Chart/PieChart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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()
Binary file added Data Visualisation/Scatter Plot/ScatterPlot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions Data Visualisation/Ternary Plots/TernaryPlots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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()
25 changes: 25 additions & 0 deletions Data Visualisation/Waterfall Chart/WaterfallChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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()