Duncan Moseley
Duncan Moseley

Reputation: 21

Mpltern hexbin and tribin ternary plots do not reflect actual data

I have some data that I want to plot as a ternary hexbin or tribin plot. When I plot it using a scatter plot, it looks like I expect it to. Here is the scatter plot of the data I expect to see.

ax.scatter(x1,y1,z1)

Ternary scatter plot of my data

However, whenever I load the same data into a hexbin or tribin plot, the binned intensity does not overlap with the points in the scatter plot.

ax.hexbin(x1,y1,z1, edgecolors="none",gridsize=20,vmax=5,zorder=0.0)

enter image description here

The code below was taken directly from the mpltern hexbin example site (Ternary Hexbin Example), and I only swapped out the data and added the scatter plot to overlay. The example code works perfectly, but swapping in my data makes it not work for some reason.

Here is the full code I am using:

import numpy as np

import matplotlib.pyplot as plt
import mpltern

x1 = np.array([0.15921388, 0.08445221, 0.13533423, 0.24502292, 0.14315514, 0.14378208,
 0.0905937, 0.13808297, 0.26968698, 0.21460839, 0.19753381, 0.39154374,
 0.2944789, 0.07735608, 0.02421507, 0.15890793, 0.08938327, 0.24203739,
 0.05313224, 0.21074095, 0.02182935, 0.12656056, 0.23842347, 0.10877017,
 0.03686441, 0.1083744, 0.30224614, 0.11176163, 0.01040438, 0.04633287,
 0.04814788, 0.25626729, 0.27124984, 0.29228856, 0.20128026, 0.15314417,
 0.03423973, 0.18703571, 0.50320241, 0.15545899, 0.22140219, 0.15753903,
 0.23184372, 0.17803931, 0.18755939, 0.2624067, 0.1440943, 0.02479316,
 0.21877641, 0.07915115])

y1 = np.array([0.03095992, 0.02485942, 0.00461012, 0.05415974, 0.00641977, 0.0075788,
 0.0134618, 0.00568952, 0.03612804, 0.00746038, 0.00676633, 0.01774103,
 0.01147181, 0.03701774, 0.00521707, 0.01513134, 0.01096237, 0.00535175,
 0.01933876, 0.01067182, 0.00671298, 0.01124348, 0.02042159, 0.01474262,
 0.06801241, 0.04752748, 0.00732321, 0.01774961, 0.02490424, 0.00562966,
 0.01450898, 0.00662498, 0.01217311, 0.00875899, 0.00708021, 0.01435426,
 0.01067889, 0.01273073, 0.01441814, 0.01066786, 0.01154695, 0.01158576,
 0.01315231, 0.00783604, 0.00777104, 0.00740172, 0.0158397, 0.14350677,
 0.00932028, 0.02426256])

z1 = np.array([0.00589924, 0.0057058, 0.00533584, 0.01385247, 0.00517615, 0.01156184,
 0.01189617, 0.00616605, 0.02759438, 0.01694141, 0.00507685, 0.01977934,
 0.01012728, 0.01097368, 0.00841697, 0.01136306, 0.00441427, 0.0087905,
 0.09940766, 0.01501123, 0.00605385, 0.01732032, 0.00804425, 0.0076006,
 0.00622514, 0.02512553, 0.0088141, 0.01543971, 0.01515265, 0.00890357,
 0.0410794, 0.00780079, 0.01436306, 0.03417111, 0.01696163, 0.01495142,
 0.09817156, 0.01281905, 0.01656083, 0.01404464, 0.00711828, 0.00759094,
 0.00899801, 0.02024836, 0.00412182, 0.00507957, 0.00991598, 0.00700659,
 0.00667614, 0.02504912])

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

ax.scatter(x1,y1,z1, color="C3", marker="x")
ax.hexbin(x1,y1,z1, edgecolors="none",gridsize=20,vmax=5,zorder=0.0)

plt.show()

enter image description here

I have tried different formats for the data. It produces the same result if it is a list, np.array, or dataframe column. The length of the data also does not affect it. It produced the same result in the full length of 1700. The tribin plot produces a similar result.

Upvotes: 1

Views: 202

Answers (0)

Related Questions