Comments (6)
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.
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.
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.
#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.
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.
This could be related to this matplotlib error: matplotlib/matplotlib#2935
from python-ternary.
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 thelinewidth
to0.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:
Zoomed-in shrunk in Illustrator example w/ edgecolor=None
:
from python-ternary.
Related Issues (20)
- Alternate orientation hexagon HOT 1
- ternary does not seem to use third axis value when plotting lines HOT 3
- Scatter creates equilateral plot HOT 1
- Question on ternary heatmap plot HOT 1
- Can not set the limits of each axis? HOT 1
- Heatmap scale greater than 1 vs less than equal to 1 HOT 4
- Cut off top of triangle? HOT 5
- Problem in making the ternary heatmap if the key interval is not 1. HOT 1
- TernaryAxesSubplot.scatter() skips first default color in version 1.0.8 HOT 1
- How to plot the Ternary Choropleth Map? HOT 3
- Heatmap polygon triangles and gridlines don't meet exactly HOT 4
- Blank Heatmap HOT 6
- Plot Blocking Option
- Custom Axis Directions HOT 2
- Cannot set transparent background HOT 1
- Issues with corner label positions under panning/zooming HOT 4
- change font, and output an equilateral triangle HOT 2
- Can't find a way that works to reduce label overlap. HOT 2
- Update installation metadata
- Remove number
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-ternary.