Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools.make_subplots titles don't respect row_width/column_width #1229

Closed
jonmmease opened this issue Oct 19, 2018 · 3 comments
Closed

tools.make_subplots titles don't respect row_width/column_width #1229

jonmmease opened this issue Oct 19, 2018 · 3 comments
Labels
bug something broken
Milestone

Comments

@jonmmease
Copy link
Contributor

The plotly.tools.make_subplots function supports adding titles to subplots by carefully placing annotations. make_subplots also supports a row_width /column_width parameter to specify non-uniform subplot widths/heights.

But it looks like the subplot title placing logic does not take row_width /column_width into account:

row_width:

from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[0, 1, 2],
    y=[10, 11, 12]
)
trace2 = go.Scatter(
    x=[2, 3, 4],
    y=[100, 110, 120],
)
trace3 = go.Scatter(
    x=[3, 4, 5],
    y=[1000, 1100, 1200],
)
fig = tools.make_subplots(rows=3, cols=1,
                          shared_xaxes=True,
                          vertical_spacing=0.1,
                          subplot_titles=('subtitle 1', 'subtitle 2', 'subtitle 3'),
                          row_width=[0.2, 0.4, 0.2]
                         )

fig.append_trace(trace1, 3, 1)
fig.append_trace(trace2, 2, 1)
fig.append_trace(trace3, 1, 1)

fig['layout'].update(height=600, width=600, title='Subplots with Shared X-Axes')
go.FigureWidget(fig)

newplot 23

column_width:

from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[0, 1, 2],
    y=[10, 11, 12]
)
trace2 = go.Scatter(
    x=[2, 3, 4],
    y=[100, 110, 120],
)
trace3 = go.Scatter(
    x=[3, 4, 5],
    y=[1000, 1100, 1200],
)
fig = tools.make_subplots(rows=1, cols=3,
                          shared_xaxes=True,
                          vertical_spacing=0.1,
                          subplot_titles=('subtitle 1', 'subtitle 2', 'subtitle 3'),
                          column_width=[0.2, 0.4, 0.2]
                         )

fig.append_trace(trace1, 1, 3)
fig.append_trace(trace2, 1, 2)
fig.append_trace(trace3, 1, 1)

fig['layout'].update(height=600, width=600, title='Subplots with Shared X-Axes')
go.FigureWidget(fig)

newplot 24

@jonmmease jonmmease added bug something broken make_subplots labels Oct 19, 2018
@jonmmease
Copy link
Contributor Author

From @Kully's comment in #896

plotly.figure_factory.utils.annotation_dict_for_label needs to use horizontal_spacing/vertical_spacing for calculations on where to draw labels for a subplot.

@Kully
Copy link
Contributor

Kully commented Oct 24, 2018

I'll make a PR for this.

@jonmmease
Copy link
Contributor Author

Done in #1245 and will be released in 3.4.0. Great work @Kully!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

No branches or pull requests

2 participants