pythonmatplotlibinsets

How to edit the axis values manually while plotting insets in matplotlib


I want to edit the axis values while plotting a graph with insets in matplotlib. I know how to do it when it's a regular plot but I can't seem to figure this out. I have attached a graph with inset below. enter image description here

Here, I want to change the values 0.0 and 1.0 on the x-axis to 0 and 1. In the y-axis, I want to change 1.0 and 2.0 to just 1 and 2. I want to do a similar thing to the inset graph too. I hope my question is clear and I am looking forward to your response.

Thank you.


Solution

  • You can edit, e.g. the x axis ticklabels by ax.set_xticklabels(). As mentioned in the corresponding docs you also should use ax.set_xticks() to fix the tick positions.

    For both axes:

    # Assuming that ax is the plot's axis
    ax.set_xticks(range(3))
    ax.set_xticklabels((0, 0.5, 1))
    
    ax.set_yticks(range(6))
    ax.set_yticklabels((1, 1.2, 1.4, 1.6, 1.8, 2))