From: Jianbao T. <jia...@gm...> - 2012-10-05 16:44:27
|
Hi, I am working on a time-series data browser based on matplotlib. In general, it shows a N_row x 1_col stack of axes, which share the x axis, the time axis. It is nice that matplotlib offers the sharex option so that the data can be zoomed simultaneously in time. However, one problem with the sharex option is that it not only shares the axis range (or limits, if you will), but also the axis appearance, which is not always desirable. In my case, I want the tick labels to be shown only on the bottom subplot. However, that doesn't seem to be achievable with sharex. The follow snippet demonstrates my example: #------------------------- code -------------------------------------------- import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212, sharex=ax1) ax1.get_xaxis().set_ticklabels([]) # This also suppresses x tick labels of ax2. fig.canvas.draw() #-------------------------- end of code ------------------------------------ Is there a workaround, hopefully simple and straightforward, to share range (or limits) only among axes? Better yet, can this feature be added, like a keyword sharexrange, in the future, if it is not already there? Of course, the situation should be similar for y axis, too. Thank you very much. Jianbao |
From: Damon M. <dam...@gm...> - 2012-10-05 16:53:41
|
On Fri, Oct 5, 2012 at 5:44 PM, Jianbao Tao <jia...@gm...> wrote: > Hi, > > I am working on a time-series data browser based on matplotlib. In general, > it shows a N_row x 1_col stack of axes, which share the x axis, the time > axis. It is nice that matplotlib offers the sharex option so that the data > can be zoomed simultaneously in time. However, one problem with the sharex > option is that it not only shares the axis range (or limits, if you will), > but also the axis appearance, which is not always desirable. In my case, I > want the tick labels to be shown only on the bottom subplot. However, that > doesn't seem to be achievable with sharex. > > The follow snippet demonstrates my example: > #------------------------- code -------------------------------------------- > import matplotlib.pyplot as plt > fig = plt.figure() > ax1 = fig.add_subplot(211) > ax2 = fig.add_subplot(212, sharex=ax1) > > ax1.get_xaxis().set_ticklabels([]) # This also suppresses x tick labels of > ax2. > fig.canvas.draw() > #-------------------------- end of code ------------------------------------ > > Is there a workaround, hopefully simple and straightforward, to share range > (or limits) only among axes? Better yet, can this feature be added, like a > keyword sharexrange, in the future, if it is not already there? Of course, > the situation should be similar for y axis, too. > > Thank you very much. > > Jianbao This was the first hit in a google search: http://stackoverflow.com/questions/4209467/matplotlib-share-x-axis-but-dont-show-x-axis-tick-labels-for-both-just-one -- Damon McDougall http://www.damon-is-a-geek.com B2.39 Mathematics Institute University of Warwick Coventry West Midlands CV4 7AL United Kingdom |
From: Jianbao T. <jia...@gm...> - 2012-10-05 17:07:05
|
Works like a charm. :-) Thank you so much, Damon. Jianbao On Fri, Oct 5, 2012 at 10:53 AM, Damon McDougall <dam...@gm...>wrote: > On Fri, Oct 5, 2012 at 5:44 PM, Jianbao Tao <jia...@gm...> wrote: > > Hi, > > > > I am working on a time-series data browser based on matplotlib. In > general, > > it shows a N_row x 1_col stack of axes, which share the x axis, the time > > axis. It is nice that matplotlib offers the sharex option so that the > data > > can be zoomed simultaneously in time. However, one problem with the > sharex > > option is that it not only shares the axis range (or limits, if you > will), > > but also the axis appearance, which is not always desirable. In my case, > I > > want the tick labels to be shown only on the bottom subplot. However, > that > > doesn't seem to be achievable with sharex. > > > > The follow snippet demonstrates my example: > > #------------------------- code > -------------------------------------------- > > import matplotlib.pyplot as plt > > fig = plt.figure() > > ax1 = fig.add_subplot(211) > > ax2 = fig.add_subplot(212, sharex=ax1) > > > > ax1.get_xaxis().set_ticklabels([]) # This also suppresses x tick labels > of > > ax2. > > fig.canvas.draw() > > #-------------------------- end of code > ------------------------------------ > > > > Is there a workaround, hopefully simple and straightforward, to share > range > > (or limits) only among axes? Better yet, can this feature be added, like > a > > keyword sharexrange, in the future, if it is not already there? Of > course, > > the situation should be similar for y axis, too. > > > > Thank you very much. > > > > Jianbao > > This was the first hit in a google search: > > http://stackoverflow.com/questions/4209467/matplotlib-share-x-axis-but-dont-show-x-axis-tick-labels-for-both-just-one > > -- > Damon McDougall > http://www.damon-is-a-geek.com > B2.39 > Mathematics Institute > University of Warwick > Coventry > West Midlands > CV4 7AL > United Kingdom > |