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

Heatmap polygon triangles and gridlines don't meet exactly #196

Open
RihuiAn opened this issue Aug 2, 2022 · 4 comments
Open

Heatmap polygon triangles and gridlines don't meet exactly #196

RihuiAn opened this issue Aug 2, 2022 · 4 comments

Comments

@RihuiAn
Copy link

RihuiAn commented Aug 2, 2022

1
2

@marcharper
Copy link
Owner

Yes, this is known (#44).

@RihuiAn
Copy link
Author

RihuiAn commented Aug 11, 2022

So, do you have any good solutions?

I don't know how to fix it by slightly moving the lines outward by the line-width.

@marcharper
Copy link
Owner

Can you post the code that generated the plot?

@RihuiAn
Copy link
Author

RihuiAn commented Aug 23, 2022

def Color_point(x, z, y, scale):
w = 255
x_color = x * w / float(scale)
y_color = y * w / float(scale)
z_color = z * w / float(scale)
r = math.fabs(w - y_color) / w
g = math.fabs(w - x_color) / w
b = math.fabs(w - z_color) / w
return (r, g, b, 1.)

def Generate_heatmap_data(scale):
from ternary.helpers import simplex_iterator
d = dict()
for (i, j, k) in simplex_iterator(scale):
d[(i, j, k)] = Color_point(i, j, k, scale)
return d

offset, r, s = 0.3, 0.02, 100
x, y = (np.sqrt(3) + 1) * r, -2 * r
ct, cd, cq, c = 'r', 'y', 'b', '#f0f0f0'
fig, tax = ternary.figure(scale=s)
data = Generate_heatmap_data(scale=100)
tax.heatmap(data, style='dual-triangular', use_rgba=True, colorbar=False)
tax.boundary(linewidth=2, zorder=3)
tax.set_background_color(color=c, alpha=0.2)
tax.gridlines(multiple=20, linewidth=1, alpha=1,
horizontal_kwargs={'color': cd},
left_kwargs={'color': ct},
right_kwargs={'color': cq})
tax.top_corner_label('Dependence', fontweight='bold', position=(0 - 0.06 - x, 1 + 0.12 + 2 * x, 0), rotation=0,
color=cd)
tax.left_corner_label('Low streamflow', fontweight='bold', position=(0 - 0.05 - x, 0 + 0.05 + y, 0), rotation=-45,
color=cq)
tax.right_corner_label('High temperature', fontweight='bold', position=(1 + x, 0 + 0.05 + y, 0), rotation=45, color=ct)
tax.right_axis_label('Relative $R_D$', offset=offset, color=cd)
tax.left_axis_label('Relative $R_{LQ}$', offset=offset, color=cq)
tax.bottom_axis_label('Relative $R_{HT}$', offset=offset, color=ct)
tax.ticks(axis='lbr', multiple=20, linewidth=1.5, offset=0.025)
tax.get_axes().axis('off')
tax.clear_matplotlib_ticks()
fig.set_facecolor('#f0f0f0')
tax.show()

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