コネクターとスニペット
コネクターとスニペット
Code Snippet / plotlyで美しいチャートを作成する
plotlyで作成した綺麗なチャートをデータアプリで活用する
Code
Python
import pandas as pd
import plotly.express as px
import morph
from morph import MorphGlobalContext
@morph.func
def create_plotly_chart(context: MorphGlobalContext):
data = pd.DataFrame({
"city": [
"Los Angeles", "San Francisco", "San Diego", "Sacramento",
"Houston", "Dallas", "Austin", "San Antonio",
"Miami", "Orlando", "Tampa", "Jacksonville",
"New York", "Buffalo", "Rochester", "Syracuse",
"Chicago", "Springfield", "Peoria", "Naperville"
],
"state": [
"California", "California", "California", "California",
"Texas", "Texas", "Texas", "Texas",
"Florida", "Florida", "Florida", "Florida",
"New York", "New York", "New York", "New York",
"Illinois", "Illinois", "Illinois", "Illinois"
],
"population": [
3980400, 883305, 1423851, 508529,
2328000, 1343000, 964300, 1532200,
470914, 285713, 399700, 903889,
8399000, 256304, 206284, 142749,
2716000, 116250, 112936, 147122
]
})
df = data.groupby("state").sum(["population"]).reset_index()
fig = px.bar(df, x="state", y="population")
return fig
MDX
export const title = "Plotlyで綺麗なチャートを作成する"
# Plotlyチャートのサンプルデモ
このサンプルコードはPlotlyで作成したチャートのサンプルデモです。
<Embed
loadData="create_plotly_chart"
height={400}
/>