MCPcopy
hub / github.com/matplotlib/matplotlib / test_margins

Function test_margins

lib/matplotlib/tests/test_axes.py:7084–7117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7082
7083
7084def test_margins():
7085 # test all ways margins can be called
7086 data = [1, 10]
7087 xmin = 0.0
7088 xmax = len(data) - 1.0
7089 ymin = min(data)
7090 ymax = max(data)
7091
7092 fig1, ax1 = plt.subplots(1, 1)
7093 ax1.plot(data)
7094 ax1.margins(1)
7095 assert ax1.margins() == (1, 1)
7096 assert ax1.get_xlim() == (xmin - (xmax - xmin) * 1,
7097 xmax + (xmax - xmin) * 1)
7098 assert ax1.get_ylim() == (ymin - (ymax - ymin) * 1,
7099 ymax + (ymax - ymin) * 1)
7100
7101 fig2, ax2 = plt.subplots(1, 1)
7102 ax2.plot(data)
7103 ax2.margins(0.5, 2)
7104 assert ax2.margins() == (0.5, 2)
7105 assert ax2.get_xlim() == (xmin - (xmax - xmin) * 0.5,
7106 xmax + (xmax - xmin) * 0.5)
7107 assert ax2.get_ylim() == (ymin - (ymax - ymin) * 2,
7108 ymax + (ymax - ymin) * 2)
7109
7110 fig3, ax3 = plt.subplots(1, 1)
7111 ax3.plot(data)
7112 ax3.margins(x=-0.2, y=0.5)
7113 assert ax3.margins() == (-0.2, 0.5)
7114 assert ax3.get_xlim() == (xmin - (xmax - xmin) * -0.2,
7115 xmax + (xmax - xmin) * -0.2)
7116 assert ax3.get_ylim() == (ymin - (ymax - ymin) * 0.5,
7117 ymax + (ymax - ymin) * 0.5)
7118
7119
7120def test_margin_getters():

Callers

nothing calls this directly

Calls 5

subplotsMethod · 0.45
plotMethod · 0.45
marginsMethod · 0.45
get_xlimMethod · 0.45
get_ylimMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…