我正在尝试用三元相图来计算我的原子组成,这是我的照片
我希望将我的刻度放在三元相图(即那些三角轴)而不是 x 和 y 轴上的刻度上。有没有办法将刻度放在三角轴而不是轴 x 和 y 上?如何在保留标签的同时删除 x 轴和 y 轴?
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri
def plot_ticks(start, stop, tick, n):
r = np.linspace(0, 1, n+1)
x = start[0] * (1 - r) + stop[0] * r
x = np.vstack((x, x + tick[0]))
y = start[1] * (1 - r) + stop[1] * r
y = np.vstack((y, y + tick[1]))
plt.plot(x, y, 'k', lw=1)
n = 5
tick_size = 0.1
margin = 0.05
# define corners of triangle
left = np.r_[0, 0]
right = np.r_[1, 0]
top = np.r_[0.5, np.sqrt(3)*0.576]
triangle = np.c_[left, right, top, left]
# define corners of triangle
left = np.r_[0, 0]
right = np.r_[1, 0]
top = np.r_[0.5, np.sqrt(3)*0.576]
triangle = np.c_[left, right, top, left]
# define vectors for ticks
bottom_tick = 0.8264*tick_size * (right - top) / n
right_tick = 0.8264*tick_size * (top - left) / n
left_tick = 0.8264*tick_size * (left - right) / n
# first load some data: format x1,x2,x3,value
test_data = np.array([[4,0,0,2.238],
[0,4,0,2.315],
[0,0,4,2.147],
[3,1,0,2.494],
[2,2,0,2.190],
[2,2,0,2.632],
[3,0,1,2.173],
[2,0,2,2.329],
[1,0,3,2.526],
[0,3,1,2.365],
[0,2,2,2.220],
[0,1,3,2.080],
[2,1,1,2.231],
[1,2,1,2.291],
[1,1,2,2.088]])
#Define twin axis
#ax = plt.gca()
fig, ax = plt.subplots()
plot_ticks(left, right, bottom_tick, n)
plot_ticks(right, top, right_tick, n)
plot_ticks(left, top, left_tick, n)
#ax2 = ax.twinx()
# barycentric coords: (a,b,c)
a=test_data[:,0]
b=test_data[:,1]
c=test_data[:,2]
# values is stored in the last column
v = test_data[:,-1]
# translate the data to cartesian corrds
x = 0.5 * ( 2.*b+c ) / ( a+b+c )
y = 0.576*np.sqrt(3) * c / (a+b+c)
# create a triangulation out of these points
T = tri.Triangulation(x,y)
# plot the contour
plt.tricontourf(x,y,T.triangles,v,cmap='jet')
# create the grid
corners = np.array([[0, 0], [1, 0], [0.5, np.sqrt(3)*0.576]])
triangle = tri.Triangulation(corners[:, 0], corners[:, 1])
# creating the grid
refiner = tri.UniformTriRefiner(triangle)
trimesh = refiner.refine_triangulation(subdiv=4)
#plotting the mesh and caliberate the axis
plt.triplot(trimesh,'k--')
#plt.title('Binding energy peratom of Al-Ti-Ni clusters')
ax.set_xlabel('Al-Ti',fontsize=12,color='black')
ax.set_ylabel('Ti-Ni',fontsize=12,color='black')
ax2 = ax.twinx()
ax2.set_ylabel('Al-Ni',fontsize=12,color='black')
plt.gcf().text(0.07, 0.05, 'Ti', fontsize=12,color='black')
plt.gcf().text(0.93, 0.05, 'Al', fontsize=12,color='black')
plt.gcf().text(0.5, 0.9, 'Ni', fontsize=12,color='black')
#set scale for axis
ax.set_xlim(1, 0)
ax.set_ylim(0, 1)
ax2.set_ylim(1, 0)
cax = plt.axes([0.75, 0.55, 0.055, 0.3])
plt.colorbar(cax=cax,format='%.3f')
plt.savefig("AID.png", dpi=1000)
plt.show()