{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyNqpViyago/JXFficnYyZP7"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["# Plotly Mechanics\n","\n","Plotly.js, the JavaScript library `plotly` is based on understands figures as trees with named nodes called attributes. The root node of the tree has three top-level attributes.\n","\n","- The top-level ***`data`*** attribute consists of a list of dicts referred to as traces.\n"," - Each trace has a plot type (scatter, bar, pie, etc.), and is drawn on a single subplot. Traces can have a single legend, and other attributes depending on trace type.\n","\n","- The top-level ***`layout`*** attribute is referred to as \"the layout\" and consists of a dict with attributes that control non-data parts of the figure. Parts of the figure governed by the `layout` attribute include:\n"," - Dimensions and margins\n"," - Templates, fonts, colors, hover labels\n"," - Titles and legends\n"," - Non-data marks such as annotations, shapes, and images\n"," - Controls like buttons, toggles, menus, or sliders\n","\n","- The top-level ***`frames`*** attribute does not exist for all types of plots. `frames` consists of a list of dicts that define sequential frames in an animated plot. Each frame in the sequence has its own `data` attribute (and other parameters).\n","\n","When building a figure, you do not have to populate every attribute of every object. The JavaScript layer can compute default values for some unspecified attributes.\n","\n","Let's look at an example for a simple line plot, using `plotly`:"],"metadata":{"id":"mSrqJA12YpJj"}},{"cell_type":"code","source":["import plotly.express as px # import statement\n","fig = px.line(x=[\"a\",\"b\",\"c\"], y=[1,3,2], title=\"sample figure\") # figure with sample data\n","fig # show figure"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":542},"id":"Lr3BUpN6YuE2","executionInfo":{"status":"ok","timestamp":1706148950528,"user_tz":300,"elapsed":160,"user":{"displayName":"Katherine Walden","userId":"17094108395123900917"}},"outputId":"b1c2ee38-46c7-4d6b-fefd-b16680dbd60b"},"execution_count":7,"outputs":[{"output_type":"display_data","data":{"text/html":["\n","
\n","\n","