Beispiel #1
0
def test_legend():
    fig = plt.figure()
    ax = fig.add_subplot(projection='ternary')

    for seed in [1, 9, 6, 8]:
        ax.scatter(*get_scatter_points(11, seed=seed), alpha=0.5, label=seed)

    ax.legend()
Beispiel #2
0
    def test_scatter_color(self):
        t, l, r = get_scatter_points()
        fig = plt.figure()
        fig.subplots_adjust(left=0.075, right=0.85)
        ax = fig.add_subplot(111, projection='ternary')
        sc = ax.scatter(t, l, r, c=range(len(t)))
        cax = ax.inset_axes([1.05, 0.1, 0.05, 0.9], transform=ax.transAxes)
        colorbar = fig.colorbar(sc, cax=cax)
        colorbar.set_label('Count', rotation=270, va='baseline')

        ax.set_tlabel('Top')
        ax.set_llabel('Left')
        ax.set_rlabel('Right')
spaced triangular grid) can result in difficulties and data misrepresentation.

Here we illustrate how the ternary heatmaps for pyrolite are constructed using an
irregualr triangulated grid and log transforms, and how this avoids some of the
potential issues of the methods mentioned above.
"""
#######################################################################################
# Let's first get some data to deal with. :mod:`mpltern` has a conventient dataset
# which we can use here:
#
import numpy as np
import pandas as pd
from mpltern.ternary.datasets import get_scatter_points

np.random.seed(43)
df = pd.DataFrame(np.array([*get_scatter_points(n=80)]).T,
                  columns=["A", "B", "C"])
df = df.loc[(df > 0.1).all(axis=1), :]
#######################################################################################
# From this dataset we'll generate a
# :func:`~pyrolite.plot.density.ternary.ternary_heatmap`, which is the basis
# for ternary density diagrams via :func:`~pyrolite.plot.pyrochem.density`:
#
from pyrolite.comp.codata import ILR, inverse_ILR
from pyrolite.plot.density.ternary import ternary_heatmap

coords, H, data = ternary_heatmap(
    df.values,
    bins=10,
    mode="density",
    remove_background=True,
Beispiel #4
0
"""
=======
Scatter
=======

Scatter plots can be done using ``ax.quiver``.
"""
import numpy as np

import matplotlib.pyplot as plt
from mpltern.ternary.datasets import get_scatter_points

t0, l0, r0 = get_scatter_points(100, seed=19)
t1, l1, r1 = get_scatter_points(100, seed=68)

dt = t1 - t0
dl = l1 - l0
dr = r1 - r0

length = np.sqrt(dt**2 + dl**2 + dr**2)

fig = plt.figure(figsize=(10.8, 4.8))
fig.subplots_adjust(left=0.075, right=0.85, wspace=0.3)

ax = fig.add_subplot(121, projection='ternary')
pc = ax.scatter(t0, l0, r0)
pc = ax.scatter(t1, l1, r1)

ax = fig.add_subplot(122, projection='ternary')
pc = ax.scatter(t0, l0, r0, c=length)
Beispiel #5
0
"""
======
Legend
======

The legend can be put using ``ax.legend`` in the same way as Matplotlib.
"""
import matplotlib.pyplot as plt
from mpltern.ternary.datasets import get_scatter_points

ax = plt.subplot(projection='ternary')

for seed in [1, 9, 6, 8]:
    ax.scatter(*get_scatter_points(11, seed=seed), alpha=0.5, label=seed)

ax.legend()

plt.show()
Beispiel #6
0
 def test_scatter(self):
     t, l, r = get_scatter_points()
     fig = plt.figure()
     ax = fig.add_subplot(projection='ternary')
     ax.scatter(t, l, r)