Giter Club home page Giter Club logo

Comments (6)

AlexanderZeilmann avatar AlexanderZeilmann commented on June 30, 2024 1

I was able to fix the overlap of the triangles in the interior by replacing https://github.com/marcharper/python-ternary/blob/master/ternary/heatmapping.py#L260

ax.fill(xs, ys, facecolor=color, edgecolor=color)

with

ax.fill(xs, ys, facecolor=color, edgecolor=color, linewidth=0.01)

I think the problem is, that the linewidth is too thick and this leads to a large overlap and misalignment of the triangles.
Setting the linewidth to 0.0 is however also not a good idea, because then a small white boundary is visible between the triangles.

At least for my small toy example setting the linewidth fixed the problem.

from python-ternary.

marcharper avatar marcharper commented on June 30, 2024

Hi @JoshuaMeyers,

Thanks for the report. Can you post a screenshot/image, and if possible, a small data set that reproduces the issue?

from python-ternary.

JoshuaMeyers avatar JoshuaMeyers commented on June 30, 2024

Hey Marc,

Sorry that was a lazy report!
Here is some simplified code and an example image.
I have not included a dataset, any should recreate the issue.

If you zoom in on this image. You will see that the corners of the triangles do not meet each other.

Hope this is more helpful.

image

screen shot 2016-04-07 at 15 04 22

#PMI ternary density plot
#set up figure
figure, ax = plt.subplots()
tax = ternary.TernaryAxesSubplot(ax=ax, scale=scale)
plt.axis('off') #turn border off

figure.set_size_inches(15.3, 14)
tax.boundary(linewidth=1.5)

#make colormap with white zero value (or more accurately any value below vmin)
cmap_whiteZero = matplotlib.cm.get_cmap('Spectral_r')
cmap_whiteZero.set_under('w')
eps = np.spacing(0.0)

#plot ternary heatmap
tax.heatmap(log_dict, style="t", cmap=cmap_whiteZero, vmin=eps, colorbar=True) # style can be t, d, or h
# tax.gridlines(color="0.2", multiple=1, linewidth=0.8, linestyle='-') #uncomment for gridlines
figure.gca().invert_yaxis()

plt.savefig('/Users/jmeyers/Desktop/myfig.pdf')

from python-ternary.

marcharper avatar marcharper commented on June 30, 2024

Thanks. Some of this is simply because of how matplotlib draws lines. I may be able to fix the corners. The other edge artifacts are because of the line width of the border -- the thickness of the border lines are covering up part of the corners of the interior colored trianges. This could be fixed by slightly moving the lines outward by the line-width. I'll have to think about how to do that for an arbitrary scale factor.

You might have better results in the meantime by setting the border to have smaller line-width.

As for the odd interior overlaps, I'll have to investigate cause -- I suspect it's something like rounding errors on the polygon coordinates.

from python-ternary.

svrnwnsch avatar svrnwnsch commented on June 30, 2024

This could be related to this matplotlib error: matplotlib/matplotlib#2935

from python-ternary.

fairliereese avatar fairliereese commented on June 30, 2024

I was able to fix the overlap of the triangles in the interior by replacing https://github.com/marcharper/python-ternary/blob/master/ternary/heatmapping.py#L260

ax.fill(xs, ys, facecolor=color, edgecolor=color)

with

ax.fill(xs, ys, facecolor=color, edgecolor=color, linewidth=0.01)

I think the problem is, that the linewidth is too thick and this leads to a large overlap and misalignment of the triangles. Setting the linewidth to 0.0 is however also not a good idea, because then a small white boundary is visible between the triangles.

At least for my small toy example setting the linewidth fixed the problem.

Setting edgecolor=None without a linewidth argument does not result in any whitespace for me. Might be worth trying that. FWIW I'm using matplotlib ver. 3.2.2.

ax.fill(xs, ys, facecolor=color, edgecolor=None)

It's also worth noting that this also solves an issue that I encountered when trying to resize the PDF version of this plot in Adobe Illustrator. Illustrator does not resize lines by default but does resize shapes. So when you shrink the ternary heatmap, the stroke widths on the lines stay the same; exacerbating the non-overlapping shapes issue.

Zoomed-in shrunk in Illustrator example w/o any changes:
Screen Shot 2022-08-24 at 12 16 13 PM

Zoomed-in shrunk in Illustrator example w/ edgecolor=None:
Example w/ edgecolor=None

from python-ternary.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.