How to create a triple contour plot in Python?

I have a dataset as follows (in Python):

import numpy as np A = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0, 0.1, 0.2, 0.3, 0.4, 0.2, 0.2, 0.05, 0.1]) B = np.array([0.9, 0.7, 0.5, 0.3, 0.1, 0.2, 0.1, 0.15, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]) C = np.array([0, 0.1, 0.2, 0.3, 0.4, 0.2, 0.2, 0.05, 0.1, 0.9, 0.7, 0.5, 0.3, 0.1, 0.2, 0.1, 0.15, 0]) D = np.array([1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2]) 

I am trying to create triple plots with matplotlib as shown in the figure ( source ). Axes are the values โ€‹โ€‹of A, B, C and D, which should be indicated by contours, and the points should be marked as in the figure.

enter image description here

Is it possible to create such graphs in matplotlib or with Python?

+8
python matplotlib graph plot contour
source share
2 answers

You can try something like this:

 import numpy as np import matplotlib.pyplot as plt import matplotlib.tri as tri # first load some data: format x1,x2,x3,value test_data = np.array([[0,0,1,0], [0,1,0,0], [1,0,0,0], [0.25,0.25,0.5,1], [0.25,0.5,0.25,1], [0.5,0.25,0.25,1]]) # 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.5*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) # create the grid corners = np.array([[0, 0], [1, 0], [0.5, np.sqrt(3)*0.5]]) triangle = tri.Triangulation(corners[:, 0], corners[:, 1]) # creating the grid refiner = tri.UniformTriRefiner(triangle) trimesh = refiner.refine_triangulation(subdiv=4) #plotting the mesh plt.triplot(trimesh,'k--') plt.show() 

Some Simple Triangular plot

Note that you can remove the x, y axes by doing:

 plt.axis('off') 

However, for the triangular axis + tags and ticks, I do not know yet, but if someone has a solution, I will take it;)

Best

Julien

+4
source share

Yes, they can; There are at least a few packages that will help.

Once I tried to put them together on the blog, Triple Charts . Be sure to check out the various links and comments.

These seem to be the best options for Python:

In another SO question, there are several suggestions: Library / tool for drawing ternary / triangular graphs [closed] .

+3
source share

All Articles