{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyPCnDQgvE0eG/4j3EbbcH4R"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["# Plotly Express\n","\n","The `plotly.express` module contains functions that can create entire figures at once. `plotly.express` functions are designed to be a user-friendly point of entry to the `plotly` package. A graph object is created as part of any `plotly.express` function, but the point of the `plotly.express` function is to significantly reduce the amount of code needed to create, customize, and render the graph object."],"metadata":{"id":"yB7l4gpBZNkz"}},{"cell_type":"markdown","source":["## Scatterplot Workflows\n","\n","For example, to create a scatterplot using `plotly.express`, we use the `px.scatter()` function, which takes values for the `X` and `Y` axis.\n","\n","Without any additional arguments, the default formatting and style options are applied."],"metadata":{"id":"Y7iv9NGvZJGq"}},{"cell_type":"code","source":["import plotly.express as px # import statement\n","fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16]) # create figure\n","fig # show figure"],"metadata":{"id":"j2khLMawZh5l"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Everything from tick marks to axis labels to grid lines to hover labels has been generated by the `plotly.express` defaults. To create a scatterplot from data stored in a `DataFrame`, the same general syntax specifying `X` and `Y` values still applies.\n","\n","Let's look at a `DataFrame` example."],"metadata":{"id":"SXTEkZSpZoDP"}},{"cell_type":"code","source":["df = px.data.iris() # load data\n","df # inspect data"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":444},"id":"3UEsyFFkZnn-","executionInfo":{"status":"ok","timestamp":1706148997882,"user_tz":300,"elapsed":384,"user":{"displayName":"Katherine Walden","userId":"17094108395123900917"}},"outputId":"fcc707cc-d66a-479a-d054-308d7bab0ac2"},"execution_count":4,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" sepal_length sepal_width petal_length petal_width species \\\n","0 5.1 3.5 1.4 0.2 setosa \n","1 4.9 3.0 1.4 0.2 setosa \n","2 4.7 3.2 1.3 0.2 setosa \n","3 4.6 3.1 1.5 0.2 setosa \n","4 5.0 3.6 1.4 0.2 setosa \n",".. ... ... ... ... ... \n","145 6.7 3.0 5.2 2.3 virginica \n","146 6.3 2.5 5.0 1.9 virginica \n","147 6.5 3.0 5.2 2.0 virginica \n","148 6.2 3.4 5.4 2.3 virginica \n","149 5.9 3.0 5.1 1.8 virginica \n","\n"," species_id \n","0 1 \n","1 1 \n","2 1 \n","3 1 \n","4 1 \n",".. ... \n","145 3 \n","146 3 \n","147 3 \n","148 3 \n","149 3 \n","\n","[150 rows x 6 columns]"],"text/html":["\n","
\n"," | sepal_length | \n","sepal_width | \n","petal_length | \n","petal_width | \n","species | \n","species_id | \n","
---|---|---|---|---|---|---|
0 | \n","5.1 | \n","3.5 | \n","1.4 | \n","0.2 | \n","setosa | \n","1 | \n","
1 | \n","4.9 | \n","3.0 | \n","1.4 | \n","0.2 | \n","setosa | \n","1 | \n","
2 | \n","4.7 | \n","3.2 | \n","1.3 | \n","0.2 | \n","setosa | \n","1 | \n","
3 | \n","4.6 | \n","3.1 | \n","1.5 | \n","0.2 | \n","setosa | \n","1 | \n","
4 | \n","5.0 | \n","3.6 | \n","1.4 | \n","0.2 | \n","setosa | \n","1 | \n","
... | \n","... | \n","... | \n","... | \n","... | \n","... | \n","... | \n","
145 | \n","6.7 | \n","3.0 | \n","5.2 | \n","2.3 | \n","virginica | \n","3 | \n","
146 | \n","6.3 | \n","2.5 | \n","5.0 | \n","1.9 | \n","virginica | \n","3 | \n","
147 | \n","6.5 | \n","3.0 | \n","5.2 | \n","2.0 | \n","virginica | \n","3 | \n","
148 | \n","6.2 | \n","3.4 | \n","5.4 | \n","2.3 | \n","virginica | \n","3 | \n","
149 | \n","5.9 | \n","3.0 | \n","5.1 | \n","1.8 | \n","virginica | \n","3 | \n","
150 rows × 6 columns
\n","