Revision: 8166 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8166&view=rev Author: leejjoon Date: 2010-03-02 01:47:48 +0000 (Tue, 02 Mar 2010)
Log Message: ----------- update axes_grid.axislines doc. Modified Paths: -------------- trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/demo_ticklabel_direction.py trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/axislines.rst Added Paths: ----------- trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step01.py trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step02.py trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step03.py trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step04.py trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction01.py trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction02.py trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction03.py Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step01.py =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step01.py (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step01.py 2010-03-02 01:47:48 UTC (rev 8166) @@ -0,0 +1,25 @@ +import matplotlib.pyplot as plt +import mpl_toolkits.axes_grid.axislines as axislines + +def setup_axes(fig, rect): + ax = axislines.Subplot(fig, rect) + fig.add_axes(ax) + + ax.set_ylim(-0.1, 1.5) + ax.set_yticks([0, 1]) + + ax.axis[:].set_visible(False) + + ax.axis["x"] = ax.new_floating_axis(1, 0.5) + ax.axis["x"].set_axisline_style("->", size=1.5) + + return ax + +fig = plt.figure(figsize=(3,2.5)) +fig.subplots_adjust(top=0.8) +ax1 = setup_axes(fig, "111") + +ax1.axis["x"].set_axis_direction("left") + + +plt.show() Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step02.py =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step02.py (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step02.py 2010-03-02 01:47:48 UTC (rev 8166) @@ -0,0 +1,36 @@ +import matplotlib.pyplot as plt +import mpl_toolkits.axes_grid.axislines as axislines + +def setup_axes(fig, rect): + ax = axislines.Subplot(fig, rect) + fig.add_axes(ax) + + ax.set_ylim(-0.1, 1.5) + ax.set_yticks([0, 1]) + + #ax.axis[:].toggle(all=False) + #ax.axis[:].line.set_visible(False) + ax.axis[:].set_visible(False) + + ax.axis["x"] = ax.new_floating_axis(1, 0.5) + ax.axis["x"].set_axisline_style("->", size=1.5) + + return ax + +fig = plt.figure(figsize=(6,2.5)) +fig.subplots_adjust(bottom=0.2, top=0.8) + +ax1 = setup_axes(fig, "121") +ax1.axis["x"].set_ticklabel_direction("+") +ax1.annotate("ticklabel direction=$+$", (0.5, 0), xycoords="axes fraction", + xytext=(0, -10), textcoords="offset points", + va="top", ha="center") + +ax2 = setup_axes(fig, "122") +ax2.axis["x"].set_ticklabel_direction("-") +ax2.annotate("ticklabel direction=$-$", (0.5, 0), xycoords="axes fraction", + xytext=(0, -10), textcoords="offset points", + va="top", ha="center") + + +plt.show() Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step03.py =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step03.py (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step03.py 2010-03-02 01:47:48 UTC (rev 8166) @@ -0,0 +1,40 @@ +import matplotlib.pyplot as plt +import mpl_toolkits.axes_grid.axislines as axislines + +def setup_axes(fig, rect): + ax = axislines.Subplot(fig, rect) + fig.add_axes(ax) + + ax.set_ylim(-0.1, 1.5) + ax.set_yticks([0, 1]) + + #ax.axis[:].toggle(all=False) + #ax.axis[:].line.set_visible(False) + ax.axis[:].set_visible(False) + + ax.axis["x"] = ax.new_floating_axis(1, 0.5) + ax.axis["x"].set_axisline_style("->", size=1.5) + + return ax + +fig = plt.figure(figsize=(6,2.5)) +fig.subplots_adjust(bottom=0.2, top=0.8) + +ax1 = setup_axes(fig, "121") +ax1.axis["x"].label.set_text("Label") +ax1.axis["x"].toggle(ticklabels=False) +ax1.axis["x"].set_axislabel_direction("+") +ax1.annotate("label direction=$+$", (0.5, 0), xycoords="axes fraction", + xytext=(0, -10), textcoords="offset points", + va="top", ha="center") + +ax2 = setup_axes(fig, "122") +ax2.axis["x"].label.set_text("Label") +ax2.axis["x"].toggle(ticklabels=False) +ax2.axis["x"].set_axislabel_direction("-") +ax2.annotate("label direction=$-$", (0.5, 0), xycoords="axes fraction", + xytext=(0, -10), textcoords="offset points", + va="top", ha="center") + + +plt.show() Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step04.py =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step04.py (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/axis_direction_demo_step04.py 2010-03-02 01:47:48 UTC (rev 8166) @@ -0,0 +1,54 @@ +import matplotlib.pyplot as plt +import mpl_toolkits.axes_grid.axislines as axislines + +def setup_axes(fig, rect): + ax = axislines.Subplot(fig, rect) + fig.add_axes(ax) + + ax.set_ylim(-0.1, 1.5) + ax.set_yticks([0, 1]) + + ax.axis[:].set_visible(False) + + ax.axis["x1"] = ax.new_floating_axis(1, 0.3) + ax.axis["x1"].set_axisline_style("->", size=1.5) + + ax.axis["x2"] = ax.new_floating_axis(1, 0.7) + ax.axis["x2"].set_axisline_style("->", size=1.5) + + return ax + +fig = plt.figure(figsize=(6,2.5)) +fig.subplots_adjust(bottom=0.2, top=0.8) + +ax1 = setup_axes(fig, "121") +ax1.axis["x1"].label.set_text("rotation=0") +ax1.axis["x1"].toggle(ticklabels=False) + +ax1.axis["x2"].label.set_text("rotation=10") +ax1.axis["x2"].label.set_rotation(10) +ax1.axis["x2"].toggle(ticklabels=False) + +ax1.annotate("label direction=$+$", (0.5, 0), xycoords="axes fraction", + xytext=(0, -10), textcoords="offset points", + va="top", ha="center") + +ax2 = setup_axes(fig, "122") + +ax2.axis["x1"].set_axislabel_direction("-") +ax2.axis["x2"].set_axislabel_direction("-") + +ax2.axis["x1"].label.set_text("rotation=0") +ax2.axis["x1"].toggle(ticklabels=False) + +ax2.axis["x2"].label.set_text("rotation=10") +ax2.axis["x2"].label.set_rotation(10) +ax2.axis["x2"].toggle(ticklabels=False) + + +ax2.annotate("label direction=$-$", (0.5, 0), xycoords="axes fraction", + xytext=(0, -10), textcoords="offset points", + va="top", ha="center") + + +plt.show() Modified: trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/demo_ticklabel_direction.py =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/demo_ticklabel_direction.py 2010-03-01 15:58:51 UTC (rev 8165) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/demo_ticklabel_direction.py 2010-03-02 01:47:48 UTC (rev 8166) @@ -33,8 +33,8 @@ ax.axis["right"].set_axis_direction("left") ax.axis["top"].set_axis_direction("bottom") -ax.axis["left"].major_ticklabels.set_pad(0) -ax.axis["bottom"].major_ticklabels.set_pad(10) +#ax.axis["left"].major_ticklabels.set_pad(0) +#ax.axis["bottom"].major_ticklabels.set_pad(10) Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction01.py =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction01.py (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction01.py 2010-03-02 01:47:48 UTC (rev 8166) @@ -0,0 +1,15 @@ +import matplotlib.pyplot as plt +import mpl_toolkits.axes_grid.axislines as axislines + +fig = plt.figure(figsize=(4,2.5)) +ax1 = fig.add_subplot(axislines.Subplot(fig, "111")) +fig.subplots_adjust(right=0.8) + +ax1.axis["left"].major_ticklabels.set_axis_direction("top") +ax1.axis["left"].label.set_text("Label") + +ax1.axis["right"].label.set_visible(True) +ax1.axis["right"].label.set_text("Label") +ax1.axis["right"].label.set_axis_direction("left") + +plt.show() Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction02.py =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction02.py (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction02.py 2010-03-02 01:47:48 UTC (rev 8166) @@ -0,0 +1,21 @@ + +import matplotlib.pyplot as plt +import mpl_toolkits.axes_grid.axislines as axislines + +def setup_axes(fig, rect): + ax = axislines.Subplot(fig, rect) + fig.add_subplot(ax) + + ax.set_yticks([0.2, 0.8]) + ax.set_xticks([0.2, 0.8]) + + return ax + +fig = plt.figure(1, figsize=(4, 2)) +ax = setup_axes(fig, "111") + +ax.axis[:].major_ticks.set_tick_out(True) + +plt.show() + + Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction03.py =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction03.py (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/figures/simple_axis_direction03.py 2010-03-02 01:47:48 UTC (rev 8166) @@ -0,0 +1,31 @@ + +import matplotlib.pyplot as plt +import mpl_toolkits.axes_grid.axislines as axislines + +def setup_axes(fig, rect): + ax = axislines.Subplot(fig, rect) + fig.add_subplot(ax) + + ax.set_yticks([0.2, 0.8]) + ax.set_xticks([0.2, 0.8]) + + return ax + +fig = plt.figure(1, figsize=(5, 2)) +fig.subplots_adjust(wspace=0.4, bottom=0.3) + +ax1 = setup_axes(fig, "121") +ax1.set_xlabel("X-label") +ax1.set_ylabel("Y-label") + +ax1.axis[:].invert_ticklabel_direction() + +ax2 = setup_axes(fig, "122") +ax2.set_xlabel("X-label") +ax2.set_ylabel("Y-label") + +ax2.axis[:].major_ticks.set_tick_out(True) + +plt.show() + + Modified: trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/axislines.rst =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/axislines.rst 2010-03-01 15:58:51 UTC (rev 8165) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/axislines.rst 2010-03-02 01:47:48 UTC (rev 8166) @@ -102,7 +102,52 @@ The ticklabels and axislabel of the top and the right axis are set to not visible. +For example, if you want to change the color attributes of +major_ticklabels of the bottom x-axis :: + ax.axis["bottom"].major_ticklabels.set_color("b") + +Similarly, to make ticklabels invisible :: + + ax.axis["bottom"].major_ticklabels.set_visible(False) + +AxisAritst provides a helper method to control the visibility of ticks, ticklabels, and label. To make ticklabel invisible, :: + + ax.axis["bottom"].toggle(ticklabels=False) + +To make all of ticks, ticklabels, and (axis) label invisible :: + + ax.axis["bottom"].toggle(all=False) + +To turn all off but ticks on :: + + ax.axis["bottom"].toggle(all=False, ticks=True) + +To turn all on but (axis) label off :: + + ax.axis["bottom"].toggle(all=True, label=False)) + + +ax.axis's __getitem__ method can take multiple axis names. For +example, to turn ticklabels of "top" and "right" axis on, :: + + ax.axis["top","right"].toggle(ticklabels=True)) + +Note that 'ax.axis["top","right"]' returns a simple proxy object that translate above code to something like below. :: + + for n in ["top","right"]: + ax.axis[n].toggle(ticklabels=True)) + +So, any return values in the for loop are ignored. And you shoud not +use it anything more than a simple method. + +Like the list indexing ":" means all items, i.e., :: + + ax.axis[:].major_ticks.set_color("r") + +changes tick color in all axis. + + HowTo ===== @@ -138,25 +183,149 @@ To change the pad between ticklabels and axis label, axis.label.set_pad method. -Examples -======== -Adjusting axis_direction ------------------------- +Rotaion and Alignment of TickLabels +=================================== +This is also quite different from the original mpl and can be +confusing. When you want to rotate the ticklabels, first consider +using "set_axis_direction" method. :: + + ax1.axis["left"].major_ticklabels.set_axis_direction("top") + ax1.axis["right"].label.set_axis_direction("left") + +.. plot:: mpl_toolkits/axes_grid/figures/simple_axis_direction01.py + +The parameter for set_axis_direction is one of ["left", "right", +"bottom", "top"]. + +You must understand some underlying concept of directions. + + 1. There is a reference direction which is defined as the direction + of the axis line with increasing coordinate. For example, the + reference direction of the left x-axis is from bottom to top. + + .. plot:: mpl_toolkits/axes_grid/figures/axis_direction_demo_step01.py + + The direction, text angle, and alignments of the ticks, ticklabels and + axis-label is determined width respect to the reference direction + + 2. *ticklabel_direction* is either the right-hand side (+) of the + reference direction or the left-hand side (-). + + .. plot:: mpl_toolkits/axes_grid/figures/axis_direction_demo_step02.py + + 3. same for the *label_direction* + + .. plot:: mpl_toolkits/axes_grid/figures/axis_direction_demo_step03.py + + 4. ticks are by default drawn toward the opposite direction of the ticklabels. + + 5. text rotation of ticklabels and label is determined in reference + to the *ticklabel_direction* or *label_direction*, + respectively. The rotation of ticklabels and tlabel is anchored. + + .. plot:: mpl_toolkits/axes_grid/figures/axis_direction_demo_step04.py + + +On the other hand, there is a concept of "axis_direction". This is a +default setting of above properties for each, "bottom", "left", "top", +and "right" axis. + + ========== =========== ========= ========== ========= ========== + ? ? left bottom right top + ---------- ----------- --------- ---------- --------- ---------- + axislabel direction '-' '+' '+' '-' + axislabel rotation 180 0 0 180 + axislabel va center top center bottom + axislabel ha right center right center + ticklabel direction '-' '+' '+' '-' + ticklabels rotation 90 0 -90 180 + ticklabel ha right center right center + ticklabel va center baseline center baseline + ========== =========== ========= ========== ========= ========== + + +And, 'set_axis_direction("top")' means to adjust the text rotation +etc, for settings suitable for "top" axis. The concept of axis +direction can be more clear with curved axis. + .. plot:: mpl_toolkits/axes_grid/figures/demo_axis_direction.py +The axis_drection can be adjusted in the AxisArtist level, or in the +level of its child arists, i.e., ticks, ticklabels, and axis-label. :: + + ax1.axis["left"].set_axis_direction("top") + +changes axis_direction of all the associated artist with the "left" +axis, while :: + + ax1.axis["left"].major_ticklabels.set_axis_direction("top") + +changes the axis_direction of only the major_ticklabels. Note that +set_axis_direction in the AxisArtist level changes the +ticklabel_direction and label_direction, while chainging the +axis_direction of ticks, ticklabels, and axis-label does not affect +them. + + +If you want to make ticks outward and ticklabels inside the axes, +use invert_ticklabel_direction method. :: + + ax.axis[:].invert_ticklabel_direction() + +A related method is "set_tick_out". It makes ticks outward (as a +matter of fact, it makes ticks toward the opposite direction of the +default direction). :: + + ax.axis[:].major_ticks.set_tick_out(True) + +.. plot:: mpl_toolkits/axes_grid/figures/simple_axis_direction03.py + + +So, in summary, + + * AxisArtist's methods + * set_axis_direction : "left", "right", "bottom", or "top" + * set_ticklabel_direction : "+" or "-" + * set_axislabel_direction : "+" or "-" + * invert_ticklabel_direction + * Ticks' methods (major_ticks and minor_ticks) + * set_tick_out : True or False + * set_ticksize : size in points + * TickLabels' methods (major_ticklabels and minor_ticklabels) + * set_axis_direction : "left", "right", "bottom", or "top" + * set_rotation : angle with respect to the renference direction + * set_ha and set_va : see below + * AxisLabels' methods (label) + * set_axis_direction : "left", "right", "bottom", or "top" + * set_rotation : angle with respect to the renference direction + * set_ha and set_va + + + Adjusting ticklabels alignment ------------------------------ +Alignment of TickLabels are treated specially. See below + .. plot:: mpl_toolkits/axes_grid/figures/demo_ticklabel_alignment.py -Adjusting ticklabels pad ------------------------- +Adjusting pad +-------------- -.. plot:: mpl_toolkits/axes_grid/figures/demo_ticklabel_direction.py +To change the pad between ticks and ticklabels :: + ax.axis["left"].major_ticklabels.set_pad(10) +Or ticklabels and axis-label :: + + ax.axis["left"].label.set_pad(10) + + +.. plot:: mpl_toolkits/axes_grid/figures/simple_axis_pad.py + + GridHelper ========== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins