Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

order of plots #121

Closed
xyko15 opened this issue Feb 13, 2020 · 3 comments
Closed

order of plots #121

xyko15 opened this issue Feb 13, 2020 · 3 comments

Comments

@xyko15
Copy link

xyko15 commented Feb 13, 2020

Thanks for the pakage, makes really nice tenary plot.
A quick question, I am trying to have a scatter plot on top of a heat map, however when I use
tax.heatmap()
tax.scatter()
the points on the scatter plot were plotted underneath the heatmap and cannot be seen. Is there a way to decide the order of plots? Here is the image where some of the red squares are underneath the heatmap.
fig1
?

@marcharper
Copy link
Owner

Can you post the full code? If you plot just the scatter are all the points in the same simplex?

@xyko15
Copy link
Author

xyko15 commented Feb 18, 2020

Below is the code, if I comment out the tax.heatmap, I will see all the points, otherwise, it will be covered by the heatmap. Thanks for the help!

#!/usr/bin/env python
# coding: utf-8


import numpy as np 
import pandas as pd
import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D
import matplotlib 
import ternary
get_ipython().run_line_magic('matplotlib', 'inline')
import matplotlib.colors as colors


FS = 14
matplotlib.rc('xtick', labelsize = FS)
matplotlib.rc('ytick', labelsize = FS)



def TenaryPlot(key,tenary_dict, cmin, cmax, comps,points, title): 
    matplotlib.rcParams['figure.dpi'] = 200
    matplotlib.rcParams['figure.figsize'] = (9, 6)

    ## Boundary and Gridlines
    scale = 10
    Fig = plt.figure()
    Fig1 = Fig.add_subplot(111)
    tax = ternary.TernaryAxesSubplot(ax=Fig1, scale=scale)
    
    #figure, tax =ternary.figure(scale=scale)
    c_min= cmin
    c_max= cmax
   

    # # Draw Boundary and Gridlines
    tax.boundary(linewidth=1.5)
    tax.gridlines(color="black", multiple=1)
    tax.gridlines(color="blue", multiple=1, linewidth=0.5)
    # # Set Axis labels and Title
    fontsize = 12
    tax.set_title(title, fontsize=fontsize)
    tax.left_axis_label(comps[2], fontsize=fontsize, offset=0.14)
    tax.right_axis_label(comps[1], fontsize=fontsize, offset=0.14)
    tax.bottom_axis_label(comps[0], fontsize=fontsize, offset=0.14)
    # # Set ticks
    tax.ticks(axis='lbr', linewidth=1, multiple=1, offset=0.03,tick_formats="%.1f")
    
    tax.heatmap(tenary_dict, cmap='gist_rainbow', vmin=c_min, vmax = c_max)
    tax.scatter(points, marker='s', color='black', s=30, label='points')
    
    # # Remove default Matplotlib Axes
    tax.clear_matplotlib_ticks()
    tax.get_axes().axis('off')
    tax.legend(loc='best')
    return Fig1


Val = {}
x1_list = np.arange(0,11)
for x1 in x1_list:
    x2_list = np.arange(0,11-x1)
    for x2 in x2_list:
        key = (x1,x2,10-x1-x2)
        Val[key] = x1 + x2 

comps=["X","Y","Z"] 

points=[]
x=[2, 2, 2, 2]
y=[0, 2, 6, 8]
z=[8, 6, 2, 0]
for i in range(len(x)):
    points.append((x[i],y[i],z[i]))


Fig1=TenaryPlot(key,Val, 0, 10, comps, points, "val\n")

plt.show()

@marcharper
Copy link
Owner

marcharper commented Mar 10, 2020

You can pass the zorder argument to the second plot to make it appear on top:

tax.scatter(points, marker='s', color='black', s=30, label='points', zorder=2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants