Home > OS >  MatplotlibDeprecationWarning: The tick1On function was deprecated in Matplotlib 3.1 and will be remo
MatplotlibDeprecationWarning: The tick1On function was deprecated in Matplotlib 3.1 and will be remo

Time:01-01

How to update depreciated tick1On and tick2On in matplotlib?

    # Turn off all the ticks
    for t in ax.xaxis.get_major_ticks():
        t.tick1On = False
        t.tick2On = False
    for t in ax.yaxis.get_major_ticks():
        t.tick1On = False
        t.tick2On = False

Warnings

/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:151: MatplotlibDeprecationWarning: 
The tick1On function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use Tick.tick1line.set_visible instead.
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:152: MatplotlibDeprecationWarning: 
The tick2On function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use Tick.tick2line.set_visible instead.
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:154: MatplotlibDeprecationWarning: 
The tick1On function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use Tick.tick1line.set_visible instead.
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:155: MatplotlibDeprecationWarning: 
The tick2On function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use Tick.tick2line.set_visible instead.

Updating the code as per warnings throwing an error

    # Turn off all the ticks
    for t in ax.xaxis.get_major_ticks():
        t.Tick.tick1line.set_visible = False
        t.Tick.tick2line.set_visible = False
    for t in ax.yaxis.get_major_ticks():
        t.Tick.tick1line.set_visible = False
        t.Tick.tick2line.set_visible = False
<ipython-input-5-674bddf7d454> in pretty_plot_confusion_matrix(df_cm, annot, cmap, fmt, fz, lw, cbar, figsize, show_null_values, pred_val_axis)
    149     # Turn off all the ticks
    150     for t in ax.xaxis.get_major_ticks():
--> 151         t.Tick.tick1line.set_visible = False
    152         t.Tick.tick2line.set_visible = False
    153     for t in ax.yaxis.get_major_ticks():

AttributeError: 'XTick' object has no attribute 'Tick'

I'm able to hide these depreciation warnings using

import warnings
warnings.filterwarnings("ignore", category=UserWarning)

But I want to update it with latest compatibility. The complete code can be found here confusion_matrix_pretty_print.py

CodePudding user response:

I think the error message meant for you to substitute like so:

for t in ax.xaxis.get_major_ticks():
    t.tick1line.set_visible(False)
    t.tick2line.set_visible(False)
  • Related