1/18/2024 0 Comments Matplotlib subplot share yThen you can play with subplotadjust (), but you must be careful with making space in a symmetric way if you want to keep the solution simple. row: each subplot row will share an x- or y-axis. Example: fig, axes plt.subplots (ncols2, sharexTrue, shareyTrue,figsize (8,4)) fig.subplotsadjust (0,0,1,1,0,0) As Benjamin Bannier points out, as a drawback you have zero margins. False or none: each subplot x- or y-axis will be independent. You would need to do the same for the y axis and also for minor ticks in case it's needed. True or all: x- or y-axis will be shared among all subplots. Note that in the above I only changed the ticker for the x axis and also only for the major ticks. To later turn other subplots' ticklabels on, use tickparams. Similarly, when subplots have a shared y-axis along a row, only the y tick labels of the first column subplot are created. Xfmt = ()Ī_major_formatter(xfmt)Īxes.plot(np.random.randn(10)*100+100, np.linspace(-3,3,10), When subplots have a shared x-axis along a column, only the x tick labels of the bottom subplot are created. # The new ticker needs new locator and formatters # Now remove axes from the grouper for xaxisĪxes.get_shared_x_axes().remove(axes) set a new Ticker with the respective new locator and formatterįig, axes = plt.subplots(3, 4, sharex='row', sharey='row', squeeze=False)Īx.plot(*np.random.randn(2,10), marker="o", ls="").1 2 3 4 5 6 7 8 9 10 11 12 13 import matplotlib.pyplot as plt import numpy as np x np.arange (-6, 6, 0.1) y1 np.sin (x) y2 np.cos (x) fig, ax plt.subplots (2, 1, sharex True) ax 0.plot (x, y1) ax 1.plot (x, y2) plt. The problem is (as points out) that the ticker is still the same for all axes. To share the x-axis, all you need to do is pass in the extra parameter sharex True. As points out in the their answer, you can use ax.get_shared_x_axes() to obtain a Grouper object that contains all the linked axes, and then.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |