0
0

plotly_3d

Last updated at Posted at 2024-01-16
import streamlit as st
import pandas as pd
from pathlib import Path

import plotly.graph_objects as go
import plotly.express as px



def main():

    st.header('Powerd by Plotly')

    # データ取得処理
    df1 = pd.read_excel('positions.xlsx')


    # 3D散布図を作成
    fig = px.scatter_3d(df1,
                        x='X', y='Y', z='Z',
                        title='3D Point Cloud',
                        color='category'
                        )
    
    fig2 = px.scatter_3d(df1, x='X', y='Y', z='Z', 
                         color='mass', 
                         symbol='category', 
                         size='mass',
                         color_continuous_scale=['grey', 'red'], 
                         labels={'mass': 'Mass'})

    # シンボルを全てのデータポイントに円に設定
    fig2.update_traces(marker=dict(symbol='circle'))

    # カラーバーの設定
    fig2.update_layout(coloraxis_colorbar=dict(title='Mass'))

    fig2.update_layout(legend_orientation="h")

    # マーカーサイズ設定
    fig.update_traces(marker_size=5)

    # 3Dサーフェスを追加
    fig.add_trace(go.Mesh3d(x=[0, 10, 0, 10],
                            y=[0, 0, 10, 10],
                            z=[0, 0, 0, 0],
                            opacity=0.5,
                            color='rgba(0, 0, 255, 0.8)'  # RGB値を変更して色を濃くする
    ))


    # レイアウトの調整
    fig.update_layout(
        scene=dict(
            xaxis=dict(range=[-100, 100]),
            yaxis=dict(range=[-100, 100]),
            zaxis=dict(range=[-100, 100])
        ),
        width=1000, # グラフの幅と高さの設定
        height=1000,
        hoverlabel_font_size=20
    )



    # グラフの表示
    st.plotly_chart(fig2, use_container_width=True)
    st.divider()
    st.dataframe(df1.head())


if __name__ == '__main__':
    main()


import streamlit as st
import pandas as pd
from pathlib import Path

import plotly.graph_objects as go
import plotly.express as px



def main():

    st.header('Powerd by Plotly')

    # データ取得処理(stの変数に応じてデータ取得後にフィルタリングする)
    df1 = pd.read_excel('positions.xlsx')

    # 選択した条件でフィルター
    selected_group_list = st.multiselect('左の条件でフィルターします',options=['GroupA', 'GroupB'], default=['GroupA'])

    # 3D散布図を作成 
    fig2 = px.scatter_3d(df1, x='X', y='Y', z='Z', 
                         color='mass', 
                         symbol='category', 
                         size='mass',
                         color_continuous_scale=['grey', 'red'], 
                         labels={'mass': 'Mass'})

    # シンボルを全てのデータポイントに円に設定
    fig2.update_traces(marker=dict(symbol='circle'))

    # カラーバーの設定
    fig2.update_layout(coloraxis_colorbar=dict(title='Mass'))

    fig2.update_layout(legend_orientation="h")

    # マーカーサイズ設定
    # fig.update_traces(marker_size=5)

    # 3Dサーフェスを追加
    fig2.add_trace(go.Mesh3d(x=[0, 50, 0, 50],
                            y=[0, 0, 50, 50],
                            z=[0, 0, 0, 0],
                            opacity=0.5,
                            color='rgba(0, 0, 255, 0.8)'  # RGB値を変更して色を濃くする
    ))

    # レイアウトの調整
    fig2.update_layout(
        scene=dict(
            xaxis=dict(range=[-100, 100]),
            yaxis=dict(range=[-100, 100]),
            zaxis=dict(range=[-100, 100])
        ),
        width=1000, # グラフの幅と高さの設定
        height=1000,
        hoverlabel_font_size=20
    )



    # グラフの表示
    st.plotly_chart(fig2, use_container_width=True)
    st.divider()
    st.dataframe(df1.head())


if __name__ == '__main__':
    main()

image.png


puts 'code block.'

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0