plotly_visualization 예시 코드

2023. 10. 30. 12:42개발

복습용!


# plotly_subplots
import plotly.graph_objs as go
from plotly.subplots import make_subplots

# make_subplots 함수를 사용하여 subplot을 생성합니다.
fig = make_subplots(rows=2, cols=2,  # 2x2 그리드 생성
                    subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4"))

# 첫 번째 subplot에 그래프 추가
trace1 = go.Scatter(x=[1, 2, 3], y=[4, 5, 6])
fig.add_trace(trace1, row=1, col=1)
fig.update_layout(title='Population of USA States')


fig = px.scatter(gapminder, x= '', y = '', size = '', color='' , hover_name='', log_x=True, size_max=60, trendline='lowess', facet_col='', facet_col_wrap=4, stackgroup=''

fig = go.Figure(data=go.Scatter(y = np.random.randn(400).cumsum(),
                                mode='markers',
                                marker=dict(size=12,
                                            color=np.random.randn(400).cumsum(),
                                            colorscale='YlOrRd',
                                            showscale=True)))


fig.update_traces(hoverinfo='text+name', mode='lines+markers', line_shape='vhv', 'linear', 'spline')
fig.update_layout(legend=dict(y=0.5, traceorder='reversed', font_size=16), yaxis_range(0,100), , yaxis=dict(type='', range=['',''], ticksuffix='%', categoryorder='category ascending', 'total descending', categoryarray=['',''])

fig = px.scatter_matrix(iris, dimensions=['',''], color=''


fig = px.line(x='', y='', label=dict(x='', y=''), range_x=['',''])
fig.update_xaxes(rangeslider_visible=True)

px.area(gapminder, x='', y='', color='', line_group='')

fig = go.Figure()
fig.add_trace(go.Scatter(x='',y='', fill = 'tozeroy', 'tonexty', mode='none'


fig = px.bar(tips, x='', y='', color='', barmode='group', 'relative', 'stack', 'overlay', height=400, category_orders=dict(day=['',''], time=['','']), orientation='h', animation_frame='', animation_group='', range_y=['','']


fig =px.box(tips, x='', y='', color='', points='all', notched=True, hover_data=[''], ,  
fig.add_trace(go.Box(x=x2, boxpoints='all', jitter=0.3, pointpos=-1.8))

fig = px.histogram(tips, x='', nbins=20, histnorm='probability density', opacity=0.8, color_discrete_sequence=['deepskyblue', 'crimson'], histfunc = 'avg', 'sum' , marginal='rug')


fig = ff.create_distplot(data, group_labels, bin_size=0.2, show_hist, curve, rug=False 


fig = go.Figure(data=go.Heatmap(x=w, y=t, z=n))
fig = ff.create_annotated_heatmap(x=w,y=t,z=n)
fig = px.density_heatmap(iris, x='petal_length', y='petal_width',
                         nbinsx=20, nbinsy=20,
                         color_continuous_scale='viridis')


fig = px.pie(gapminder_asia, values='pop', names='country',
             hover_data=['lifeExp'], labels=dict(lifeExp='life expectancy'))
fig.update_traces(textposition='inside', textinfo='percent+label')
fig.update_layout(uniformtext_minsize=12, uniformtext_mode='hide')




fig = px.parallel_categories(tips,
                             dimensions=['sex', 'smoker', 'day'],
                             color='size',
                             color_continuous_scale = 'viridis')

fig = px.parallel_coordinates(iris, color='species_id',
                             dimensions=['sepal_width', 'sepal_length',
                                         'petal_width', 'petal_length'],
                             color_continuous_scale='armyrose',
                              color_continuous_midpoint=2)

fig = ff.create_dendrogram(x, color_threshold=1.6)


fig = px.scatter_mapbox(carshare, lat='centroid_lat', lon='centroid_lon',
                       color='peak_hour', size='car_hours',
                       color_continuous_scale='icefire',
                        size_max=15, zoom=10, mapbox_style='carto-positron'
                        )

fig = px.choropleth_mapbox(unemp, geojson=counties, locations='fips', color='unemp',
                           color_continuous_scale='blues',
                           range_color = (0,12),
                           mapbox_style='carto-positron',
                           zoom=3, center={'lat':37, 'lon':-95},
                           labels={'unemp': 'unemployment rate'},
                           opacity=0.5)
fig.update_layout(margin={'r':0, 't':0, 'l':0, 'b':0})



fig = px.density_mapbox(earthquakes, lat='Latitude', lon='Longitude',
                        z='Magnitude', radius=10,
                        center=dict(lat=0, lon=180), zoom=0,
                        mapbox_style='stamen-terrain')
# 텍스트 표시
fig = px.scatter(gapminder_asia_2007, x='gdpPercap', y='lifeExp',
                 text='country', log_x=True, size_max=60)
fig.update_traces(textposition='top center')
fig.update_layout(height=800)
fig.show()

'개발' 카테고리의 다른 글

파이썬 시각화  (0) 2023.11.08
소수, 약수 구하기_에라토스테네스의 체  (0) 2023.11.06
머신러닝_시각화  (0) 2023.10.31