Giter Site home page Giter Site logo

Comments (2)

Phlya avatar Phlya commented on June 11, 2024 1

Thank you, I merged your PR!

from adjusttext.

136s avatar 136s commented on June 11, 2024

I wanted deterministic output, so I added the iter_lim argument to adjust_text() function in #165.
I verified with the following code that the output does not change each time.

from pathlib import Path
from adjustText import adjust_text
import matplotlib as mpl
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import numpy as np


def draw_fig(n_points: int = 80) -> Figure:
    # like the example from https://adjusttext.readthedocs.io/en/latest/Examples.html
    np.random.seed(0)
    x, y = np.random.random((2, n_points))
    fig, ax = plt.subplots()
    ax.plot(x, y, "bo")
    texts = [ax.text(x[i], y[i], f"Text{i}") for i in range(n_points)]
    adjust_text(texts, ax=ax, iter_lim=50)
    plt.close()
    return fig


mpl.rcParams["svg.hashsalt"] = "0"  # make SVG deterministic
svg_files: list[Path] = []
for i in range(2):
    fig = draw_fig()
    filepath = Path(f"fig_{i}.svg")
    svg_files.append(filepath)
    fig.savefig(filepath, metadata={"Creator": None, "Date": None})

assert svg_files[0].read_text() == svg_files[1].read_text(), "SVG files differ"
fig_0.svg fig_1.svg
fig_0 fig_1
versions of packages in my environment
# Name                    Version                   Build  Channel
bioframe                  0.6.0                    pypi_0    pypi
matplotlib                3.8.2           py312h2e8e312_0    conda-forge
numpy                     1.26.3          py312h8753938_0    conda-forge
python                    3.12.1          h2628c8c_1_cpython    conda-forge
scipy                     1.11.4          py312h8753938_0    conda-forge

If you like this modification, please merge it!

from adjusttext.

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.