Home>
secax = ax.secondary_xaxis ('top', functions = (step2theta, theta2step))
secax.set_xlabel ('theta [deg]')


I created an x-axis with a different value at the top of the graph, but I don't know how to set the range for that axis.
If it is the default x-axis

plt.xticks (np.arange (0, 1, 0.01))


You can set the range by setting the range like this, but is it possible to specify the range in the graph created by ax.secondary_xaxis like this?
I would appreciate it if you could answer.

  • Answer # 1

    For example if we want to have a second scale for the data plotted on the xaxis.
    matplotlib.axes.Axes.secondary_xaxis

    This function, unlike the second axis that you often see (the axis that divides the scale for easier viewing in a plot with multiple data), I feel that it is an axis that looks at one data from another perspective. (Mutually convertible, such as frequency and seconds)
    Since the 1st axis is converted to create the 2nd axis, it seems that the scale of the 1st axis inevitably works on the 2nd axis as it is.

    I saw it for the first time, so I'm sorry if I made a mistake.

    Postscript

    What is this alone ...
    Isn't the function you are looking for something like the one below? (This is the vertical axis)
    How to write a Matplotlib-2 axis graph
    [Python] How to draw a graph with two axes on the left and right with matplotlib