Show/hide subplots in plotly python

Hi all,

In matplotlib, there is this functionality:

ax.set_visible(False)

which allows to show/hide plots in a subplot environment. This full example from Müller&Guido 2016 shows how it works:

from sklearn.datasets import load_iris
iris = load_iris()
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import numpy as np

X_train, X_test, y_train, y_test = train_test_split(iris['data'], iris['target'], random_state=0)

fig, ax = plt.subplots(3, 3, figsize=(15, 15))
plt.suptitle("iris_pairplot")
for i in range(3):    
    for j in range(3):        
        ax[i, j].scatter(X_train[:, j], X_train[:, i + 1], c=y_train, s=60)
        ax[i, j].set_xticks(())
        ax[i, j].set_yticks(())        
        if i == 2:            
            ax[i, j].set_xlabel(iris['feature_names'][j])        
        if j == 0:            
            ax[i, j].set_ylabel(iris['feature_names'][i + 1])        
        if j > i:            
            ax[i, j].set_visible(False)

Which gives:

Subplots to the right (j > i) are hidden.

Is there a similar function in plotly? That would be super helpful in my opinion.

Thanks in advance.

Hi @AgileBeastJr,

Are you referring to sunbathing aka something like this?

EDIT: I just noticed it’s even the same data. It’s also possible to hide the diagonal.

Thank you very much @AIMPED ! For those interested, investigating your answer redirected me to this page:

Which covers the whole topic for this kind of subplots.

Cheers!

1 Like