File size: 4,366 Bytes
b9ebe8b 1152399 b9ebe8b 4ab5104 34d9eb1 09fad03 b9ebe8b 2970f7f 4ab5104 2970f7f 4ab5104 b9ebe8b |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
import streamlit as st
import numpy as np
import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
st.set_page_config(page_title="Plotly Graphing Libraries",layout='wide')
st.markdown("WebGL Rendering with 1,000,000 Points")
import plotly.graph_objects as go
import numpy as np
N = 1000000
fig = go.Figure()
fig.add_trace(
go.Scattergl(
x = np.random.randn(N),
y = np.random.randn(N),
mode = 'markers',
marker = dict(
line = dict(
width = 1,
color = 'DarkSlateGrey')
)
)
)
#fig.show()
st.plotly_chart(fig, use_container_width=True)
st.markdown("# WebGL Graph - ScatterGL")
fig = go.Figure()
trace_num = 10
point_num = 5000
for i in range(trace_num):
fig.add_trace(
go.Scattergl(
x = np.linspace(0, 1, point_num),
y = np.random.randn(point_num)+(i*5)
)
)
fig.update_layout(showlegend=False)
#fig.show()
st.plotly_chart(fig, use_container_width=True)
st.markdown("# Treemaps: https://plotly.com/python/treemaps/")
df = px.data.gapminder().query("year == 2007")
fig = px.treemap(df, path=[px.Constant("world"), 'continent', 'country'], values='pop',
color='lifeExp', hover_data=['iso_alpha'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
#fig.show()
st.plotly_chart(fig, use_container_width=True)
st.markdown("# Sunburst: https://plotly.com/python/sunburst-charts/")
st.markdown("# Life Expectancy Sunburst")
df = px.data.gapminder().query("year == 2007")
fig = px.sunburst(df, path=['continent', 'country'], values='pop',
color='lifeExp', hover_data=['iso_alpha'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
st.plotly_chart(fig, use_container_width=True)
st.markdown("# Coffee Aromas and Tastes Sunburst")
df1 = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/sunburst-coffee-flavors-complete.csv')
df2 = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/coffee-flavors.csv')
fig = go.Figure()
fig.add_trace(go.Sunburst(
ids=df1.ids,
labels=df1.labels,
parents=df1.parents,
domain=dict(column=0)
))
fig.add_trace(go.Sunburst(
ids=df2.ids,
labels=df2.labels,
parents=df2.parents,
domain=dict(column=1),
maxdepth=2
))
fig.update_layout(
grid= dict(columns=2, rows=1),
margin = dict(t=0, l=0, r=0, b=0)
)
st.plotly_chart(fig, use_container_width=True)
# Sunburst
#data = dict(
# character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
# parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
# value=[10, 14, 12, 10, 2, 6, 6, 4, 4])
#fig = px.sunburst(
# data,
# names='character',
# parents='parent',
# values='value',
#)
#fig.show()
#st.plotly_chart(fig, use_container_width=True)
df = px.data.tips()
fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'],
values='total_bill', color='time',
color_discrete_map={'(?)':'lightgrey', 'Lunch':'gold', 'Dinner':'darkblue'})
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
#fig.show()
fig.update_traces(marker=dict(cornerradius=5))
st.plotly_chart(fig, use_container_width=True)
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/96c0bd/sunburst-coffee-flavors-complete.csv')
fig = go.Figure(go.Treemap(
ids = df.ids,
labels = df.labels,
parents = df.parents,
pathbar_textfont_size=15,
root_color="lightgrey"
))
fig.update_layout(
uniformtext=dict(minsize=10, mode='hide'),
margin = dict(t=50, l=25, r=25, b=25)
)
#fig.show()
st.plotly_chart(fig, use_container_width=True)
df = pd.read_pickle('bloom_dataset.pkl')
fig = px.treemap(df, path=[px.Constant("ROOTS"), 'Macroarea', 'Family', 'Genus', 'Language', 'dataset_name'],
values='num_bytes', maxdepth=4)
fig.update_traces(root_color="pink")
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
st.plotly_chart(fig, use_container_width=True)
|