Skip to content

Various fixes Matplotlib 3.6+ #1

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
- name: Run pre-commit
uses: pre-commit/action@v2.0.3
uses: pre-commit/action@v3.0.1

build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v2
- uses: actions/checkout@v4
# - name: Install system dependencies
# run: sudo apt-get install -y texlive-latex-base texlive-latex-extra context python3-tk
- name: Test with tox
run: |
pip install tox
tox -- --cov tikzplotlib --cov-report xml --cov-report term
- uses: codecov/codecov-action@v1
if: ${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest' }}
- uses: codecov/codecov-action@v4
if: ${{ matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest' }}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"matplotlib >= 1.4.0",
"numpy",
"Pillow",
"webcolors",
"webcolors <= 1.13.0",
]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion src/tikzplotlib/_axes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import matplotlib as mpl
import numpy as np
from matplotlib.backends.backend_pgf import (
common_texification as mpl_common_texification,
_tex_escape as mpl_common_texification,
)

from . import _color
Expand Down
33 changes: 19 additions & 14 deletions src/tikzplotlib/_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ def draw_legend(data, obj):
if alignment:
data["current axes"].axis_options.append(f"legend cell align={{{alignment}}}")

if obj._ncol != 1:
data["current axes"].axis_options.append(f"legend columns={obj._ncol}")
try:
ncols = obj._ncols
except AttributeError:
# backwards-compatibility with matplotlib < 3.6.0
ncols = obj._ncol
if ncols != 1:
data["current axes"].axis_options.append(f"legend columns={ncols}")

# Write styles to data
if legend_style:
Expand Down Expand Up @@ -117,40 +122,40 @@ def _get_location_from_best(obj):
# (or center) of the axes box.
# 1. Key points of the legend
lower_left_legend = x0_legend
lower_right_legend = np.array([x1_legend[0], x0_legend[1]], dtype=np.float_)
upper_left_legend = np.array([x0_legend[0], x1_legend[1]], dtype=np.float_)
lower_right_legend = np.array([x1_legend[0], x0_legend[1]], dtype=np.float32)
upper_left_legend = np.array([x0_legend[0], x1_legend[1]], dtype=np.float32)
upper_right_legend = x1_legend
center_legend = x0_legend + dimension_legend / 2.0
center_left_legend = np.array(
[x0_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=np.float_
[x0_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=np.float32
)
center_right_legend = np.array(
[x1_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=np.float_
[x1_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=np.float32
)
lower_center_legend = np.array(
[x0_legend[0] + dimension_legend[0] / 2.0, x0_legend[1]], dtype=np.float_
[x0_legend[0] + dimension_legend[0] / 2.0, x0_legend[1]], dtype=np.float32
)
upper_center_legend = np.array(
[x0_legend[0] + dimension_legend[0] / 2.0, x1_legend[1]], dtype=np.float_
[x0_legend[0] + dimension_legend[0] / 2.0, x1_legend[1]], dtype=np.float32
)

# 2. Key points of the axes
lower_left_axes = x0_axes
lower_right_axes = np.array([x1_axes[0], x0_axes[1]], dtype=np.float_)
upper_left_axes = np.array([x0_axes[0], x1_axes[1]], dtype=np.float_)
lower_right_axes = np.array([x1_axes[0], x0_axes[1]], dtype=np.float32)
upper_left_axes = np.array([x0_axes[0], x1_axes[1]], dtype=np.float32)
upper_right_axes = x1_axes
center_axes = x0_axes + dimension_axes / 2.0
center_left_axes = np.array(
[x0_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=np.float_
[x0_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=np.float32
)
center_right_axes = np.array(
[x1_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=np.float_
[x1_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=np.float32
)
lower_center_axes = np.array(
[x0_axes[0] + dimension_axes[0] / 2.0, x0_axes[1]], dtype=np.float_
[x0_axes[0] + dimension_axes[0] / 2.0, x0_axes[1]], dtype=np.float32
)
upper_center_axes = np.array(
[x0_axes[0] + dimension_axes[0] / 2.0, x1_axes[1]], dtype=np.float_
[x0_axes[0] + dimension_axes[0] / 2.0, x1_axes[1]], dtype=np.float32
)

# 3. Compute the distances between comparable points.
Expand Down
3 changes: 1 addition & 2 deletions src/tikzplotlib/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,7 @@ def mpl_linestyle2pgfplots_linestyle(data, line_style, line=None):
default_dashOffset, default_dashSeq = mpl.lines._get_dash_pattern(line_style)

# get dash format of line under test
dashSeq = line._us_dashSeq
dashOffset = line._us_dashOffset
dashOffset, dashSeq = line._unscaled_dash_pattern

lst = list()
if dashSeq != default_dashSeq:
Expand Down
2 changes: 1 addition & 1 deletion src/tikzplotlib/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_legend_text(obj):
if leg is None:
return None

keys = [h.get_label() for h in leg.legendHandles if h is not None]
keys = [h.get_label() for h in leg.legend_handles if h is not None]
values = [t.get_text() for t in leg.texts]

label = obj.get_label()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def plot():
]

for _ in range(N):
polygon = Polygon(np.random.rand(N, 2), True)
polygon = Polygon(np.random.rand(N, 2), closed=True)
patches.append(polygon)

colors = 100 * np.random.rand(len(patches))
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deps =
pytest
pytest-cov
pytest-codeblocks
matplotlib == 3.5.1
matplotlib
pytest-randomly
commands =
pytest {posargs} --codeblocks
Loading