def test_ternary_lim(fig_test, fig_ref): """ Check that the order of `plot` and `set_ternary_lim` does not affect the result. """ ax = fig_test.add_subplot(projection='ternary') t, l, r = get_spiral() ax.set_ternary_lim( 0.1, 0.5, # tmin, tmax 0.2, 0.6, # lmin, lmax 0.3, 0.7, # rmin, rmax ) ax.plot(t, l, r) ax.set_tlabel('Top') ax.set_llabel('Left') ax.set_rlabel('Right') ax = fig_ref.add_subplot(projection='ternary') t, l, r = get_spiral() ax.plot(t, l, r) ax.set_ternary_lim( 0.1, 0.5, # tmin, tmax 0.2, 0.6, # lmin, lmax 0.3, 0.7, # rmin, rmax ) ax.set_tlabel('Top') ax.set_llabel('Left') ax.set_rlabel('Right')
def test_data_with_five_arguments(): # When with data, the number of positional arguments must be 3 or 4. fig = plt.figure() ax = fig.add_subplot(projection='ternary') t, l, r = get_spiral() data = {'t': t, 'l': l, 'r': r} with pytest.raises(ValueError): ax.plot('t', 'l', 'r', 'foo', 'bar', data=data)
def test_aspect(): fig = plt.figure() ax = fig.add_subplot(projection='ternary') ax.plot(*get_spiral()) ax.set_aspect(1.5) ax.set_tlabel('Top') ax.set_llabel('Left') ax.set_rlabel('Right')
def test_manual_ticks(self): fig = plt.figure() ax = fig.add_subplot(projection='ternary') ax.plot(*get_spiral()) ax.grid() ax.set_tlabel('Top') ax.set_llabel('Left') ax.set_rlabel('Right') # Specify tick positions manually. ax.taxis.set_ticks([0.2, 0.4, 0.6, 0.8, 1.0]) ax.laxis.set_ticks([0.2, 0.4, 0.6, 0.8, 1.0]) ax.raxis.set_ticks([0.2, 0.4, 0.6, 0.8, 1.0])
def test_given_triangles(self, labelrotation, rotation, baseline_images): # Check if the tick-markers, tick-labels, and axis-labels are shown as # expected. fig = plt.figure() corners = ((0.5, 0.0), (1.0, 0.5), (0.0, 1.0)) ax = fig.add_subplot( projection='ternary', corners=corners, rotation=rotation) t, l, r = get_spiral() ax.plot(t, l, r) ax.set_tlabel('Top') ax.set_llabel('Left') ax.set_rlabel('Right') ax.tick_params(labelrotation=labelrotation) ax.grid()
def setUp(self): self.tlr = get_spiral()
""" ============================ With normal Matplotlib plots ============================ Ternary plots of mpltern can be combined with normal Matplotlib plots very straightforwardly. """ import matplotlib.pyplot as plt from mpltern.ternary.datasets import get_spiral t, l, r = get_spiral() fig = plt.figure(figsize=(10.8, 4.8)) # Enough space may need to make the heights of the ternary and the normal plots # the same. fig.subplots_adjust(left=0.075, right=0.95) ax = fig.add_subplot(121, projection='ternary') ax.plot(t, l, r, 'k') ax = fig.add_subplot(122) ax.plot(t) ax.plot(l) ax.plot(r) plt.show()
""" ============ Colored axes ============ You can give a different color for each axis. """ import matplotlib.pyplot as plt from mpltern.ternary.datasets import get_spiral fig = plt.figure() ax = fig.add_subplot(projection='ternary') ax.plot(*get_spiral(), color='k') ax.set_tlabel('Top') ax.set_llabel('Left') ax.set_rlabel('Right') ax.grid() # Color ticks, grids, tick-labels ax.taxis.set_tick_params(tick2On=True, colors='C0', grid_color='C0') ax.laxis.set_tick_params(tick2On=True, colors='C1', grid_color='C1') ax.raxis.set_tick_params(tick2On=True, colors='C2', grid_color='C2') # Color labels ax.taxis.label.set_color('C0') ax.laxis.label.set_color('C1') ax.raxis.label.set_color('C2')
""" ================== Arbitrary triangle ================== You can make a ternary plot on an triangle with arbitrary shape. """ import matplotlib.pyplot as plt from mpltern.ternary.datasets import get_spiral corners = ((0.0, 0.0), (0.5, 0.5), (-0.5, 1.0)) ax = plt.subplot(projection='ternary', corners=corners) ax.plot(*get_spiral()) ax.set_tlabel('Top') ax.set_llabel('Left') ax.set_rlabel('Right') ax.grid() plt.show()
def test_arguments_7(self): fig = plt.figure() ax = fig.add_subplot(projection='ternary') t, l, r = get_spiral() ax.plot(t, l, r, 'C3:', l, r, t)
def test_data(): fig = plt.figure() ax = fig.add_subplot(projection='ternary') t, l, r = get_spiral() data = {'t': t, 'l': l, 'r': r} ax.plot('t', 'l', 'r', data=data)
def test_plot(): fig = plt.figure() ax = fig.add_subplot(projection='ternary') t, l, r = get_spiral() ax.plot(t, l, r)