0

I have a bunch of Nx1 plots made of subplots (most are 7x1, but some are 5x1, etc). The idea is that there are 3 zones to be in, and 7 timed events of varying time lengths, and I want to see each timed event in order, with a plot of the time in minutes spent in a zone. I want each subplot to have the proper y axes label ticks (minutes) as well as a label (P1 through P7 in this case, but some are P1 through P5, etc), but all the x axes turned off except for the bottom one which are my own ticks, in words. I'm pulling from here and here.

The problem I have is the bottom-most subplot not only has my word text ('Zone 1', 'Zone 2'..), but also has numbers that are meaningless for me (ticks from 0 to 1), and the y axes have the subplot ticks that are correct (going from 0 to 10 or so) but also an over-all marking from 0 to 1 which is senseless. I want to nuke the senseless over-all x axis numbers, and the over-all senseless y axes numbers.

How do I remove the unwanted tick numbers from the over-all plot?

import matplotlib.pyplot as plt
import numpy as np

plotlist = [[0, 0, 690], [0, 0, 1030], [0, 0, 470], [30, 10, 730], [0, 0, 460], [20, 0, 540], [0, 0, 380]]
numpresses = 7

fig = plt.figure()

objects = ('Zone 1', 'Zone 2', 'Zone 3')
y_pos = np.arange(len(objects))
plt.title('Time spent in zones (minutes)')
plt.ylabel('Minutes spent in zone')

for subploti in range(numpresses):
    ax = fig.add_subplot(numpresses, 1, (subploti + 1))
    axes = plt.gca()
    axes.get_xaxis().set_visible(False)
    axes.set_ylabel('P %i' %(subploti + 1))

    mins = [x / 60. for x in plotlist[subploti]]
    plt.bar(y_pos, mins, align='center', alpha=0.5)

plt.xticks(y_pos, objects)
axes = plt.gca()
axes.get_xaxis().set_visible(True)



plt.show()

Plot with extraneous ticks

Manner
  • 57
  • 10
  • No, it's not the same -- that still has x axis labels on all the subplots in the photo shown. – Manner Sep 29 '17 at 16:02

1 Answers1

1

Okay, turns out the solution was using shared axes and creating the number of subplots in advance and indexing them. Needed to look harder here and here. If anyone else finds this the new code is

import matplotlib.pyplot as plt
import numpy as np

plotlist = [[0, 0, 690], [0, 0, 1030], [0, 0, 470], [30, 10, 730], [0, 0, 460], [20, 0, 540], [0, 0, 380]]
numpresses = 7

fig, axtuple = plt.subplots(numpresses, sharex=True, sharey=True) #, squeeze=True)

objects = ('Zone 1', 'Zone 2', 'Zone 3')
y_pos = np.arange(len(objects))
plt.ylabel('Minutes spent in zone')
plt.xlabel('Distances (feet)')
axtuple[0].set_title('Time spent in zones (minutes)')

for subploti in range(numpresses):
    mins = [x / 60. for x in plotlist[subploti]]
    axtuple[subploti].bar(y_pos, mins, align='center', alpha=0.5)
    axtuple[subploti].set_ylabel('P %i' %(subploti + 1))

plt.xticks(y_pos, objects)
plt.show()
Manner
  • 57
  • 10