Create 3D Scatter Plot -- Python Plotly

Поділитися
Вставка
  • Опубліковано 21 лип 2024
  • Learn to create the 3D scatter plot in under 25 lines of code. We will also animate the plot, and save as html to share with others. Lastly, we will review when it is best to use or avoid the 3D plot. Open Links below...
    View my book - The Book of Dash:
    www.amazon.com/Python-Dash-An...
    github.com/DashBookProject/Pl...
    Code:
    github.com/Coding-with-Adam/D...
    Data:
    drive.google.com/file/d/1MeFm...
    Data source:
    ourworldindata.org/
    3d Scatter Plot Documentation:
    plotly.com/python/3d-scatter-...
    plotly.com/python-api-referen...
    Plotly Marker symbol list:
    plotly.com/python/reference/#...
    Video Layout:
    00:00 What you will learn
    00:41 Goal of tutorial
    03:31 the Data
    05:41 the Code
    07:16 Fundamental 1- Creating the 3D plot
    11:38 Fundamental 2- Styling the 3D plot
    22:46 Fundamental 3- Animation of 3D plot
    30:03 Fundamental 4- Sharing your plot with others via HTML
    31:55 Fundamental 5- Do's and Dont's of 3d plotting

КОМЕНТАРІ • 35

  • @oiuchi
    @oiuchi 4 роки тому

    Best tutorials on plotly !Thanks again

  • @sacthitheranga6387
    @sacthitheranga6387 3 роки тому

    Thanks. Clearly explained and easy to follow.

  • @GeronimoAlbornoz
    @GeronimoAlbornoz 3 роки тому

    Adam, thank you very much for your tutorials. Greetings from Argentina!

    • @CharmingData
      @CharmingData  3 роки тому

      Saludos Geronimo. Vivé en Ecuador unos 3 años y siempre quería viajar a Argentina. Tal vez algún día.

    • @GeronimoAlbornoz
      @GeronimoAlbornoz 3 роки тому

      @@CharmingData Adam, si algún día venís, avisame y hacemos una presentación de dash y plotly . Acá hay una gran comunidad de Python. Yo tambien espero algún día ir a visitar NY!😁💪

  • @pipepi4888
    @pipepi4888 3 роки тому +1

    Thanks, it helped me a lot.

  • @pascal45678
    @pascal45678 2 роки тому +1

    wow... after I watched this video... I totally did not want to learn about plotly anymore... I just wanted to know how to get those brilliant sounds that appeared when the bullet list continues in the beginning of the video :D

  • @ayamyudhis9809
    @ayamyudhis9809 2 роки тому

    I want to ask is there any way to show the centroids plot (used in k-means) in the 3d scatter plot?

  • @gangminkim6553
    @gangminkim6553 3 роки тому +1

    Hi, Your contents were so helpful!!
    Is there a simple way to make a 3D-plot with same xyz-axis size? like a cube.

    • @CharmingData
      @CharmingData  3 роки тому

      Thanks Gangmin, here's an example: chart-studio.plotly.com/~empet/14165.embed

  • @asadi_888
    @asadi_888 3 роки тому

    Hi, thanks for good
    explanation. Do you know how to disable axies rotation duriong rotation of the scene >?

  • @TheSoonAnn
    @TheSoonAnn Рік тому

    very comprehensive

  • @juanpetert-yuune1708
    @juanpetert-yuune1708 11 місяців тому

    the scatter 3d doesn't show because of the log_x=True. What should i do? when i change the log into log_y and log_z it works

  • @hisyamyunus1678
    @hisyamyunus1678 3 роки тому

    how to remove axis?

  • @axe.n_
    @axe.n_ 27 днів тому

    HEYY.... CAN YOU EXPLAIN OR HELP ME TO SAVE THIS AS ANIMATION VIDEO FILE !?

  • @johnylemon473
    @johnylemon473 4 роки тому

    Keep teaching us bro, have you thought about tutorial on dash mobile app?

    • @CharmingData
      @CharmingData  4 роки тому

      Thanks Johnny. I don't believe I'm aware of that. Is that a library? Or are you just thinking how to do Dash on mobile?

    • @johnylemon473
      @johnylemon473 4 роки тому

      @@CharmingData idk, I just thinking of .

  • @sathyanarayanankulasekaran5928
    @sathyanarayanankulasekaran5928 4 роки тому

    is there a way to highlight a selected point ?

    • @CharmingData
      @CharmingData  4 роки тому +2

      Yes. You can listen to click data like this:
      @app.callback(
      [Output('click-data', 'children'),
      Output('basic-interactions', 'figure')],
      [Input('basic-interactions', 'clickData')],
      [State('basic-interactions', 'relayoutData')])
      def display_click_data(clickData, relayoutData):
      if not clickData:
      return dash.no_update, dash.no_update
      point = clickData["points"][0]
      # Do something only for a specific trace
      if point["curveNumber"] > 0:
      return dash.no_update, dash.no_update
      else:
      fig = go.Figure(go.Scatter3d(
      x=np.arange(10),
      y=np.arange(10),
      z=np.arange(10),
      mode='markers'))
      sizes = 8 * np.ones(10)
      sizes[point["pointNumber"]] = 15
      colors = ['blue',]*10
      colors[point["pointNumber"]] = 'red'
      fig.update_traces(marker_size=sizes, marker_color=colors)
      # Make sure the view/angle stays the same when updating the figure
      if relayoutData and "scene.camera" in relayoutData:
      fig.update_layout(scene_camera=relayoutData["scene.camera"])
      return json.dumps(clickData, indent=2), fig
      This is from community.plotly.com/t/highlighting-scatter3d-selection-via-callback-mesh3d-blocking-click-event/32006/2?u=adamschroeder

  • @preciousogunje5404
    @preciousogunje5404 3 роки тому

    This is awesome and i have learnt a lot so far.... I have somewhat of big data and i was looking to displaying my high dimensionality data points through through t_SNE on plotly.... any tip on how i could go about that ?

    • @CharmingData
      @CharmingData  3 роки тому

      Sorry, not sure about that, @Precious O.

  • @go1chase1the1sun1set
    @go1chase1the1sun1set 2 роки тому

    Hi can I do this with RGB values?
    X = [1,2,3,4]
    Y = [1,2,3,4]
    Z = [1,2,3,4]
    C = np.array([[0, 0, 0], [0, 0, 128], [255, 255, 102],[0, 7, 65]])
    fig = plt.figure()
    ax = fig.add_subplot(111, projection = '3d')
    ax.scatter(X, Y, Z, c = C/255.0)
    ax.set_xlabel('x axis')
    ax.set_ylabel('y axis')
    ax.set_zlabel('z axis')
    plt.show()
    this but place my whole RGB colour list in C parameter? And changew X, Y, Z to n=(how many are in the list)

  • @wadewen1008
    @wadewen1008 3 роки тому

    I'm trying to plot two sets of xyz data on the same 3D graph, Ik how to do this on pyplot but how can I do this on plotly? (I'm learning plotly bc I wanna share my graphs without sending people my whole code...)

    • @CharmingData
      @CharmingData  3 роки тому

      So you're trying to plot two separate traces?

    • @wadewen1008
      @wadewen1008 3 роки тому

      Charming Data Yes. Two traces on the same graph. They’re two sets of the same parameters but operating at different conditions, so it’s better to show them on one graph.

    • @CharmingData
      @CharmingData  3 роки тому

      @@wadewen1008 you'll have to use the fig.add_trace() function with graph objects. For example, this is how I added a trace to my code in this tutorial.
      fig.add_trace(go.Scatter3d(
      x=df['% Econ. active'],
      y=df['GDP per capita'],
      z=df['Years in school (avg)'],
      mode='markers',
      marker=dict(
      size=12,
      color="black", # set color to an array/list of desired values
      colorscale='Viridis', # choose a colorscale
      opacity=0.8
      )
      ))

    • @wadewen1008
      @wadewen1008 3 роки тому

      Charming Data for the df when reading data from the excel file, can I do df1 df2, etc? Bc the datasets aren’t from the same excel sheet

    • @CharmingData
      @CharmingData  3 роки тому

      @@wadewen1008 yes, that should be possible.

  • @Lotaristo
    @Lotaristo 2 роки тому

    Ha, in every video we can hear some police sirens XD

  • @romniyepez5206
    @romniyepez5206 Рік тому

    Please, go straight to the point....
    (5:50 You're welcome!)