Search code examples
pythonmatplotliblogarithm

What is the pyplot synonym for ax.get_xaxis?


I am trying to use ax.get_xaxis for a logarithmic plot but I don't have axes. Instead I want to use a similar matplotlib.pyplot function to just use it on the current plot but I can't seem to find it online. What would it be?

Example:

plt.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())

Solution

  • ax = plt.gca() # get current axis
    

    Now you have the axis.

    (you can use similar logic with plt.gcf() to get the current figure)