'How to change ticks of a subplot in matplotlib
I have been assigned to do a seaborn style pairplot but using matplotlib on the iris dataset. I finished all the histogram and scatterplots but I am missing one last thing. The y-ticks on the first subplot which in the seaborn pairplot show values of the scatterplot but in matplotlib can only show values of the histogram.
The expected output is:

But what I get is:

If you look at the top left corner, the ticks are different. Is there anyway I can change the tick values so that I can have 4.5 -7.5 and not the histogram values? I tried to change them manually but they do not scale the same.
Here is the code:
fig,ax = plt.subplots(4,4,figsize=(14,14))
names = ['sepal length(cm)','sepal width (cm)', 'petal length (cm)','petal width (cm)']
# plt.sca(ax[0, 0])
# plt.yticks(range(7), [4.5,5.0,5.5,6.0,6.5,7.0,7.5], color='red')
for i in range(0,len(ax)):
for j in range(len(ax)):
if i == j :
if j != 0:
ax[i][j].set_yticks([])
else:
ax[i][j].set_ylabel(names[i])
if i != 3:
ax[i][j].set_xticks([])
else:
ax[i][j].set_xlabel(names[i])
ax[i][j].hist(data[:,i],edgecolor = "black",bins=20,color='#00008B')
else:
if j != 0:
ax[i][j].set_yticks([])
else:
ax[i][j].set_ylabel(names[i])
if i != 3:
ax[i][j].set_xticks([])
else:
ax[i][j].set_xlabel(names[j])
ax[j][i].scatter(data[:50,i],data[:50,j],color='#00008B',edgecolors='black')
ax[j][i].scatter(data[51:100,i],data[51:100,j],color='r',edgecolors='black')
ax[j][i].scatter(data[100:,i],data[100:,j],color='#83f52c',edgecolors='black')
plt.subplots_adjust(wspace=0, hspace=0)`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
