How to create X-Axis at top without plotting values

Hi,

I’m trying to add a top X-Axis to a figure and I can’t seem to find a way to make it display properly through the figure settings. In my layout I have something like this:

layout = go.Layout(
                xaxis=dict(
                    tickmode='array',
                    tickvals=idx_sections * freq_adjust,
                    ticktext=section_names,

                ),
                xaxis2=XAxis(
                    overlaying='x',
                    side='top',
                    tickmode='array',
                    tickvals=idx_sections * freq_adjust,
                    ticktext=timestamps,
                    title="Timestamps",
                    showgrid=False
                )

But it only displays properly if I then add a go.Scatter object that uses xaxis='x2' for example. Even adding a figure with empty x/y values doesn’t display properly. Is it possible to directly set the range and tick locations/values before showing the figure? Any help appreciated.

Hi @tyarosevich, welcome to the forums.

I am not sure, what you want to achieve, but @vestland posted a solution for a x-axis on top, y-axis on the right:

1 Like

Hi Aimped,

Sorry if I wasn’t clear enough in my original post - I have no issue plotting with axes on the right or top. The issue I’m having is plotting TWO x-axes and ONE y-axis with a singlet set of x-y values. Essentially I want to plot a regular set of xy pairs with the y-axis on the left and x-axis at the bottom, then add an entirely new, arbitrary x-axis at the top where I can specify an arbitrary index range, ticks, and tickvalues (I want to put timestamps at the top at specific places).

It’s been my experience that I can’t make this work without plotting a second set of xy data (one hack I’ve used to make it work is to plot the first set of data again in a separate figure with an x-axis at the top, then adding this to the figure).

Hopefully that clarifies my issue, thanks.