# Coloring similar entries in a matrix with the same color

**URL:** https://discourse.julialang.org/t/coloring-similar-entries-in-a-matrix-with-the-same-color/124160
**Category:** General Usage
**Tags:** colors
**Created:** [December 24, 2024, 9:55pm UTC](https://discourse.julialang.org/t/coloring-similar-entries-in-a-matrix-with-the-same-color/124160 "2024-12-24T21:55:04Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [December 26, 2024, 2:36pm UTC](https://discourse.julialang.org/t/coloring-similar-entries-in-a-matrix-with-the-same-color/124160/9 "2024-12-26T14:36:46Z")

</div>

> [@Shuvomoy\_Das\_Gupta](#):
>
> the number of unique elements in the matrix is much smaller subject to the tolerance

Short answer: probably use `round.(A, sigdigits=2)` or similar to assign colors. (Adjust `sigdigits` as desired, or use `digits` if you want an absolute tolerance.)

Longer answer: approximate comparison is not transitive, so trying to define “uniqueness subject to a tolerance” inevitably will encounter some odd behaviors. This has been a frequently discussed topic. See, for example:

- [`unique()` with `isapprox()` instead of `isequal()` · Issue #19147 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/19147) and [Allow tolerance for `unique` · Issue #26837 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/26837)
- [Unique() to a certain tolerance? - #3 by improbable22](https://discourse.julialang.org/t/unique-to-a-certain-tolerance/23007/3)
- [How to make a Set of real values based on rtol? - #3 by djsegal](https://discourse.julialang.org/t/how-to-make-a-set-of-real-values-based-on-rtol/11769/3)
- [The test isequal(+0.0,-0.0) returns FALSE - #8 by stevengj](https://discourse.julialang.org/t/the-test-isequal-0-0-0-0-returns-false/38404/8)

---

_[View the full topic](https://discourse.julialang.org/t/coloring-similar-entries-in-a-matrix-with-the-same-color/124160)._
