-
示例圖片:
-
數(shù)據(jù)準(zhǔn)備:
- 主要模塊:pandas、matplotlib淑玫、mpltern
- 模塊安裝
pip install pandas matplotlib mpltern
- 完整代碼:
# ************************************************************************
# _*_coding:utf-8_*_
# Author: Pandas120 (微信)
# Desription: 繪制地球化學(xué)三角投圖巾腕、梯形圖、任意多邊形圖
# ************************************************************************
import matplotlib.pyplot as plt
import mpltern
import pandas as pd
from matplotlib.ticker import MultipleLocator
plt.rcParams['font.family'] = 'Arial Unicode MS'
plt.rcParams['font.size'] = 10
plt.rcParams["pdf.fonttype"] = 42
data = pd.read_excel('Py-data.xlsx')
#創(chuàng)建畫布大小
fig = plt.figure(figsize=(6,4))
#ternary_sum設(shè)置刻度范圍最大值
ax = plt.subplot(projection='ternary',ternary_sum=100.0)
#繪制散點
pc = ax.scatter(data['Fs'], data['Wo'], data['En'],label='samples')
#繪制內(nèi)部網(wǎng)格
ax.grid()
#截取頂部絮蒿,繪制任意多邊形修改下面參數(shù)范圍即可
ax.set_ternary_lim(
0, 50, # rmin, rmax
0, 100, # lmin, lmax
0, 100, # bmin, bmax
)
#設(shè)置三元
ax.set_tlabel("Fs")
ax.set_llabel("Wo")
ax.set_rlabel("En")
#設(shè)置刻度
ax.taxis.set_major_locator(MultipleLocator(10))
ax.laxis.set_major_locator(MultipleLocator(10))
ax.raxis.set_major_locator(MultipleLocator(10))
#設(shè)置圖例位置
ax.legend(loc=1)
plt.tight_layout()
fig.savefig('2.pdf')
plt.show()