Spaces:
Sleeping
Sleeping
File size: 890 Bytes
aeee62c 9083192 aeee62c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import random
import streamlit as st
import plotly.express as px
# Set page title
st.set_page_config(page_title="Dice-Roll-Treemap-Plotly - d100 Dice Roll Treemap Chart")
# Define function to roll a d100 dice
def roll_dice():
return random.randint(1, 100)
# Roll dice 1000 times and store results
rolls = [roll_dice() for _ in range(1000)]
# Convert rolls to counts and create dictionary
counts = {}
for roll in rolls:
if roll not in counts:
counts[roll] = 1
else:
counts[roll] += 1
# Create Plotly treemap chart using counts
fig = px.treemap(
names=[f":game_die: {roll}" for roll in counts.keys()],
parents=["Dice Rolls" for _ in counts.keys()],
values=list(counts.values()),
color=list(counts.keys()),
color_continuous_scale="YlOrRd",
title="d100 Dice Roll Treemap Chart",
)
# Render chart in Streamlit app
st.plotly_chart(fig)
|