0

This is a follow on from my Previous Question

I have the following code:

#Plot

cmap = plt.cm.GnBu_r
f, ax = plt.subplots(nrows=4,figsize=(20,10))
spec = f.add_gridspec(ncols = 1, nrows = 4, height_ratios = [1,1,1,.3])


ax0 = f.add_subplot(spec[0])
ax0 = sns.heatmap(df1,cbar=False,cmap=cmap)

ax1 = f.add_subplot(spec[1])
ax1 = sns.heatmap(df2,cbar=False,cmap=cmap)

ax2 = f.add_subplot(spec[2])
ax2 = sns.heatmap(df3,cbar=False,cmap=cmap)

ax3 = f.add_subplot(spec[3])
ax3 = sns.heatmap(df4,cbar=False,cmap=cmap)


axis = [ax0,ax1,ax2,ax3]
names = ['1', '2', '3','4']

for axi in axis:
    n = axis.index(axi)
    axi.set_title(str(names[n]))
    axi.set(xticklabels=[])
    axi.set_xlabel('')
    axi.xaxis.set_visible(False)
    h = axi.get_yticks()
    w = axi.get_xticks()
    axi.vlines(25, h[0] - 0.5, h[-1] + .5, linewidth=1, color="black")
    axi.vlines(50,h[0]-0.5,h[-1]+.5, linewidth=1, color="black")
    axi.vlines(75,h[0]-0.5,h[-1]+.5, linewidth=1, color="black")
    axi.vlines(100,h[0]-0.5,h[-1]+.5, linewidth=2, color="black")
    axi.set_ylabel('')

Which gives me the following output:

enter image description here

I have blacked out the names that I want to show but I am wondering how to hide the other x and y labels? eg all the decimals. I think they are related to the gridspec boxes for the 4 indivdual plots but i dont know how to remove them. I can remove the xticklabels and xlabel but it doesnt seem to work on the decimal points.

Summary Question: How do I remove the decimal points in the plots? Any help would be much appreciated! Thanks!

SOK
  • 1,732
  • 2
  • 15
  • 33
  • You are adding the subplots twice. Once w subplots and the second time w your add_subplot calls – Jody Klymak Jul 19 '20 at 23:33
  • thanks @JodyKlymak, that makes sense although i can't seem to be able to make it work without both? any recommendaytions to replicate the same graphy dimensions (with the height ratios) but keep the one subplot? – SOK Jul 20 '20 at 00:23
  • 1
    `f= plt.figure(figsize=(20,10))` and `spec = f.add_gridspec(ncols = 1, nrows = 4, height_ratios = [1,1,1,.3])` – Jody Klymak Jul 20 '20 at 23:00

1 Answers1

1

If I understood well, you can remove specific ticks as decribed here. By using

yticks = axi.yaxis.get_major_ticks()
yticks[k].set_visible(False)

EDITED

Here is an example

import matplotlib
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
y_dot = [0,1,2,3,4,5,6,7]
x_dot = [0,1,2,3,4,5,6,7]

xticks = ax.xaxis.get_major_ticks()

for x in x_dot:
    for y in y_dot:
        ax.plot(x, y, 'ro')
        
l_x = [1,3,5]
for element in l_x:
    xticks[element].set_visible(False)

yticks = ax.yaxis.get_major_ticks()
l_y = [2,4,6]
for element in l_y:
    yticks[element].set_visible(False)

With the following output:

enter image description here

Let's try
  • 1,044
  • 9
  • 20
  • Thanks @Let's try. When i added this in it is removing the names of the plot and not the numbers. I am trying to do the opposite but not sure how to reference the grid that contains the decimals and not the name – SOK Jul 19 '20 at 12:17
  • Even if you use `.get_major_ticks()` and `[k]` to select specific ticks? I think right now you are applying it to the whole `xaxis` and that's why it removes only the names. I will try to provide an example asap. – Let's try Jul 19 '20 at 12:39
  • Thanks! should i be replacing `k` with anything? it comes up with a `k is not defined` error – SOK Jul 19 '20 at 12:50
  • Check the example! – Let's try Jul 19 '20 at 14:17