
#Add subplot titles after figure plotly update
Now set the x-axis and y-axis titles for each subplot using the update xaxes() and update yaxes() methods to give each subplot a special title. The general title of the plot is then changed to "Trigonometric Functions" using the update layout() method.

By utilizing the row and col arguments of the add trace() method, we can define the subplot for each trace. For the three traces, we additionally supply the name parameters as "Sin(x)," "Cos(x)," and "Tan(x)," accordingly. For each of the three y1, y2, and 圓 arrays, a Scatter trace is added. With the add trace() function, each subplot is given a trace after the subplot grid has been created. Each grid subplot's titles are determined by this. The subplot titles option is additionally sent an array of three strings with the values "Sin(x)", "Cos(x)," and "Tan(x)". Using the make subplots() method, we next produce a subplot grid with one row and three columns. The sin, cos, and tan functions of the array x are represented by the three arrays y1, y2, and 圓 that we generate. The numpy library is then used to create some example data.

In order to create some example data, we also import the numpy library. Import aph objs and plotly.subplots first, as these are required libraries. Use the update_xaxes and update_yaxes methods to assign unique titles to the x-axis and y-axis of each subplot.įrom plotly.subplots import make_subplotsįig = make_subplots(rows=1, cols=3, subplot_titles=("Sin(x)", "Cos(x)",įig.add_trace(go.Scatter(x=x, y=y1, name='Sin(x)'), row=1, col=1)įig.add_trace(go.Scatter(x=x, y=y2, name='Cos(x)'), row=1, col=2)įig.add_trace(go.Scatter(x=x, y=圓, name='Tan(x)'), row=1, col=3)įig.update_layout(title_text="Trigonometric Functions")įig.update_xaxes(title_text="X-axis for Sin Wave", row=1, col=1)įig.update_xaxes(title_text="X-axis for Cos Wave", row=1, col=2)įig.update_xaxes(title_text="X-axis Tan Wave", row=1, col=3)įig.update_yaxes(title_text="Y-axis for Sin Wave", row=1, col=1)įig.update_yaxes(title_text="Y-axis for Cos Wave", row=1, col=2)įig.update_yaxes(title_text="Y-axis Tan Wave", row=1, col=3) Use the update_layout method to assign a title to the entire plot. For each subplot, pass a go.Scatter object containing the data to be plotted and a name parameter to label the data. Pass the subplot_titles parameter to give each subplot a unique title.Īdd traces to each subplot using the add_trace method.

Use the make_subplots function to create a grid of subplots with 1 row and 3 columns. Import the necessary modules - aph_objs and plotly.subplots as well as numpy.Ĭreate some data using numpy to be plotted.
#Add subplot titles after figure plotly code
In the code below we will be do the in a way like this to give each subplot a unique title − fig = make_subplots(rows=1, cols=3, subplot_titles=("Subplot 1", "Subplot 2", "Subplot 3"))īefore writing the actual code, understand the algorithm for it. The size of this array should equal the number of subplots in the grid. Subplot_titles − An array of strings that illustrates the titles of each subplot in the grid. Each element in the specs array should comprise two values: the number of rows and columns the subplot spans, respectively, and the subplot type. Specs − An array of arrays that delineates the type of each subplot in the grid. Rows − This parameter specifies the number of rows in the plot grid.Ĭols − This parameter specifies the number of columns in the plot grid. Let's delve into some of the key parameters we can manipulate with make_subplots() − The make_subplots() function is essentially a factory method that allows us to establish a plot grid with a designated number of rows and columns. SyntaxĬustomizing subplot titles in plot grids is made possible through the usage of the subplot_titles parameter, which enables us to create unique titles for each plot. Sometimes, in order to give the main story greater depth and consistency, it may be essential to give each subplot its own title. A big narrative can be broken up into multiple smaller ones using subplots. Subplot creation is one of several tools for data visualization provided by the Python library Plotly.
