Skip to content

import numpy as np #457

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

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: ci

on: [pull_request]
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
Expand Down
1 change: 1 addition & 0 deletions test/refresh_reference_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def _main():
test_modules.remove("test_deterministic_output")
test_modules.remove("test_cleanfigure")
test_modules.remove("test_context")
test_modules.remove("test_readme")

for mod in test_modules:
module = importlib.import_module(mod)
Expand Down
6 changes: 3 additions & 3 deletions test/test_annotate_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@
};
\draw[->,draw=red] (axis cs:4.5,1.5) -- (axis cs:4,1);
\draw (axis cs:4.5,1.5) node[
scale=0.5,
scale=0.65,
anchor=base west,
text=black,
rotate=0.0
]{text};
\draw[->,draw=black] (axis cs:0,1) ++(-50pt,30pt) -- (axis cs:0,1);
\draw (axis cs:0,1) ++(-50pt,30pt) node[
scale=0.5,
scale=0.65,
anchor=base west,
text=black,
rotate=0.0
]{arrowstyle};
\draw (axis cs:50,-30) node[
scale=0.5,
scale=0.65,
anchor=base west,
text=black,
rotate=0.0
Expand Down
2 changes: 1 addition & 1 deletion test/test_barchart_legend_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

\begin{axis}[
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, draw=white!80!black},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.5,0.91)}, anchor=north, draw=white!80!black},
tick align=outside,
tick pos=left,
x grid style={white!69.019608!black},
Expand Down
2 changes: 1 addition & 1 deletion test/test_deterministic_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# the same process, the order of axis parameters is deterministic.
plot_code = """
import sys
import numpy as np
import numpy as np as np
from matplotlib import pyplot as plt
import tikzplotlib

Expand Down
2 changes: 1 addition & 1 deletion test/test_hatch_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

\nextgroupplot[
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, draw=white!80!black},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.91,0.5)}, anchor=east, draw=white!80!black},
tick align=outside,
tick pos=left,
x grid style={white!69.019608!black},
Expand Down
12 changes: 6 additions & 6 deletions test/test_legend_best_location_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

\nextgroupplot[
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.03,0.97)}, anchor=north west, draw=white!80!black},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.5,0.91)}, anchor=north, draw=white!80!black},
scaled x ticks=manual:{}{\pgfmathparse{#1}},
scaled y ticks=manual:{}{\pgfmathparse{#1}},
tick align=outside,
Expand Down Expand Up @@ -117,7 +117,7 @@

\nextgroupplot[
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.03,0.03)}, anchor=south west, draw=white!80!black},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.97,0.03)}, anchor=south east, draw=white!80!black},
scaled x ticks=manual:{}{\pgfmathparse{#1}},
tick align=outside,
tick pos=left,
Expand Down Expand Up @@ -207,7 +207,7 @@

\nextgroupplot[
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.09,0.5)}, anchor=west, draw=white!80!black},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.5,0.5)}, anchor=center, draw=white!80!black},
scaled x ticks=manual:{}{\pgfmathparse{#1}},
scaled y ticks=manual:{}{\pgfmathparse{#1}},
tick align=outside,
Expand Down Expand Up @@ -282,7 +282,7 @@

\nextgroupplot[
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.5,0.09)}, anchor=south, draw=white!80!black},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.97,0.03)}, anchor=south east, draw=white!80!black},
tick align=outside,
tick pos=left,
x grid style={white!69.019608!black},
Expand Down Expand Up @@ -315,7 +315,7 @@

\nextgroupplot[
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.5,0.91)}, anchor=north, draw=white!80!black},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, draw=white!80!black},
scaled y ticks=manual:{}{\pgfmathparse{#1}},
tick align=outside,
tick pos=left,
Expand Down Expand Up @@ -349,7 +349,7 @@
\addlegendentry{UC}

\nextgroupplot[
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, draw=white!80!black},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(0.91,0.5)}, anchor=east, draw=white!80!black},
scaled y ticks=manual:{}{\pgfmathparse{#1}},
tick align=outside,
tick pos=left,
Expand Down
4 changes: 2 additions & 2 deletions test/test_text_overlay.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import matplotlib.pyplot as plt
import numpy
import numpy as np
from helpers import assert_equality


def plot():
fig = plt.figure()

xxx = numpy.linspace(0, 5)
xxx = np.linspace(0, 5)
yyy = xxx ** 2
plt.text(
1,
Expand Down
4 changes: 2 additions & 2 deletions tikzplotlib/_axes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import matplotlib as mpl
import numpy
import numpy as np
from matplotlib.backends.backend_pgf import (
common_texification as mpl_common_texification,
)
Expand Down Expand Up @@ -731,7 +731,7 @@ def _handle_linear_segmented_color_map(cmap, data):
# dimension errors or memory errors in latex)
# 0-1000 is the internal granularity of PGFplots.
# 16300 was the maximum value for pgfplots<=1.13
X = _scale_to_int(numpy.array(X), 1000)
X = _scale_to_int(np.array(X), 1000)

color_changes = []
ff = data["float format"]
Expand Down
34 changes: 17 additions & 17 deletions tikzplotlib/_color.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import matplotlib as mpl
import numpy
import numpy as np


def mpl_color2xcolor(data, matplotlib_color):
"""Translates a matplotlib color specification into a proper LaTeX xcolor."""
# Convert it to RGBA.
my_col = numpy.array(mpl.colors.ColorConverter().to_rgba(matplotlib_color))
my_col = np.array(mpl.colors.ColorConverter().to_rgba(matplotlib_color))

# If the alpha channel is exactly 0, then the color is really 'none'
# regardless of the RGB channels.
Expand All @@ -18,22 +18,22 @@ def mpl_color2xcolor(data, matplotlib_color):
# List white first such that for gray values, the combination
# white!<x>!black is preferred over, e.g., gray!<y>!black. Note that
# the order of the dictionary is respected from Python 3.6 on.
"white": numpy.array([1, 1, 1]),
"lightgray": numpy.array([0.75, 0.75, 0.75]),
"gray": numpy.array([0.5, 0.5, 0.5]),
"darkgray": numpy.array([0.25, 0.25, 0.25]),
"black": numpy.array([0, 0, 0]),
"white": np.array([1, 1, 1]),
"lightgray": np.array([0.75, 0.75, 0.75]),
"gray": np.array([0.5, 0.5, 0.5]),
"darkgray": np.array([0.25, 0.25, 0.25]),
"black": np.array([0, 0, 0]),
#
"red": numpy.array([1, 0, 0]),
"green": numpy.array([0, 1, 0]),
"blue": numpy.array([0, 0, 1]),
"brown": numpy.array([0.75, 0.5, 0.25]),
"lime": numpy.array([0.75, 1, 0]),
"orange": numpy.array([1, 0.5, 0]),
"pink": numpy.array([1, 0.75, 0.75]),
"purple": numpy.array([0.75, 0, 0.25]),
"teal": numpy.array([0, 0.5, 0.5]),
"violet": numpy.array([0.5, 0, 0.5]),
"red": np.array([1, 0, 0]),
"green": np.array([0, 1, 0]),
"blue": np.array([0, 0, 1]),
"brown": np.array([0.75, 0.5, 0.25]),
"lime": np.array([0.75, 1, 0]),
"orange": np.array([1, 0.5, 0]),
"pink": np.array([1, 0.75, 0.75]),
"purple": np.array([0.75, 0, 0.25]),
"teal": np.array([0, 0.5, 0.5]),
"violet": np.array([0.5, 0, 0.5]),
# The colors cyan, magenta, yellow, and olive are also
# predefined by xcolor, but their RGB approximation of the
# native CMYK values is not very good. Don't use them here.
Expand Down
8 changes: 4 additions & 4 deletions tikzplotlib/_image.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import matplotlib as mpl
import numpy
import numpy as np
import PIL

from . import _files
Expand Down Expand Up @@ -30,11 +30,11 @@ def draw_image(data, obj):
assert len(dims) == 3 and dims[2] in [3, 4]
# convert to PIL image
if obj.origin == "lower":
img_array = numpy.flipud(img_array)
img_array = np.flipud(img_array)

# Convert mpl image to PIL
if img_array.dtype != numpy.uint8:
img_array = numpy.uint8(img_array * 255)
if img_array.dtype != np.uint8:
img_array = np.uint8(img_array * 255)
image = PIL.Image.fromarray(img_array)

# If the input image is PIL:
Expand Down
44 changes: 22 additions & 22 deletions tikzplotlib/_legend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warnings

import numpy
import numpy as np

from . import _color as mycol

Expand Down Expand Up @@ -111,40 +111,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 = numpy.array([x1_legend[0], x0_legend[1]], dtype=numpy.float_)
upper_left_legend = numpy.array([x0_legend[0], x1_legend[1]], dtype=numpy.float_)
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_)
upper_right_legend = x1_legend
center_legend = x0_legend + dimension_legend / 2.0
center_left_legend = numpy.array(
[x0_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=numpy.float_
center_left_legend = np.array(
[x0_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=np.float_
)
center_right_legend = numpy.array(
[x1_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=numpy.float_
center_right_legend = np.array(
[x1_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=np.float_
)
lower_center_legend = numpy.array(
[x0_legend[0] + dimension_legend[0] / 2.0, x0_legend[1]], dtype=numpy.float_
lower_center_legend = np.array(
[x0_legend[0] + dimension_legend[0] / 2.0, x0_legend[1]], dtype=np.float_
)
upper_center_legend = numpy.array(
[x0_legend[0] + dimension_legend[0] / 2.0, x1_legend[1]], dtype=numpy.float_
upper_center_legend = np.array(
[x0_legend[0] + dimension_legend[0] / 2.0, x1_legend[1]], dtype=np.float_
)

# 2. Key points of the axes
lower_left_axes = x0_axes
lower_right_axes = numpy.array([x1_axes[0], x0_axes[1]], dtype=numpy.float_)
upper_left_axes = numpy.array([x0_axes[0], x1_axes[1]], dtype=numpy.float_)
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_)
upper_right_axes = x1_axes
center_axes = x0_axes + dimension_axes / 2.0
center_left_axes = numpy.array(
[x0_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=numpy.float_
center_left_axes = np.array(
[x0_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=np.float_
)
center_right_axes = numpy.array(
[x1_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=numpy.float_
center_right_axes = np.array(
[x1_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=np.float_
)
lower_center_axes = numpy.array(
[x0_axes[0] + dimension_axes[0] / 2.0, x0_axes[1]], dtype=numpy.float_
lower_center_axes = np.array(
[x0_axes[0] + dimension_axes[0] / 2.0, x0_axes[1]], dtype=np.float_
)
upper_center_axes = numpy.array(
[x0_axes[0] + dimension_axes[0] / 2.0, x1_axes[1]], dtype=numpy.float_
upper_center_axes = np.array(
[x0_axes[0] + dimension_axes[0] / 2.0, x1_axes[1]], dtype=np.float_
)

# 3. Compute the distances between comparable points.
Expand All @@ -161,7 +161,7 @@ def _get_location_from_best(obj):
10: center_axes - center_legend, # center
}
for k, v in distances.items():
distances[k] = numpy.linalg.norm(v, ord=2)
distances[k] = np.linalg.norm(v, ord=2)

# 4. Take the shortest distance between key points as the final
# location
Expand Down
6 changes: 3 additions & 3 deletions tikzplotlib/_line2d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime

import numpy
import numpy as np
from matplotlib.dates import num2date

from . import _color as mycol
Expand Down Expand Up @@ -222,7 +222,7 @@ def _table(obj, data): # noqa: C901
except AttributeError:
ydata_mask = []
else:
if isinstance(ydata_mask, numpy.bool_) and not ydata_mask:
if isinstance(ydata_mask, np.bool_) and not ydata_mask:
ydata_mask = []
elif callable(ydata_mask):
# pandas.Series have the method mask
Expand Down Expand Up @@ -268,7 +268,7 @@ def _table(obj, data): # noqa: C901

plot_table = []
table_row_sep = data["table_row_sep"]
ydata[ydata_mask] = numpy.nan
ydata[ydata_mask] = np.nan
if any(ydata_mask):
# matplotlib jumps at masked images, while PGFPlots by default interpolates.
# Hence, if we have a masked plot, make sure that PGFPlots jumps as well.
Expand Down
16 changes: 8 additions & 8 deletions tikzplotlib/_path.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import matplotlib as mpl
import numpy
import numpy as np
from matplotlib.dates import DateConverter, num2date
from matplotlib.markers import MarkerStyle

Expand Down Expand Up @@ -32,7 +32,7 @@ def draw_path(data, path, draw_options=None, simplify=None):
# The transform call yields warnings and it is unclear why. Perhaps
# the input data is not suitable? Anyhow, this should not happen.
# Comment out for now.
# vert = numpy.asarray(
# vert = np.asarray(
# _transform_to_data_coordinates(obj, [vert[0]], [vert[1]])
# )
# For path codes see: http://matplotlib.org/api/path_api.html
Expand Down Expand Up @@ -123,7 +123,7 @@ def draw_pathcollection(data, obj):

if obj.get_array() is not None:
draw_options.append("scatter")
dd = numpy.column_stack([dd, obj.get_array()])
dd = np.column_stack([dd, obj.get_array()])
labels.append("colordata" + 13 * " ")
draw_options.append("scatter src=explicit")
table_options.extend(["x=x", "y=y", "meta=colordata"])
Expand Down Expand Up @@ -159,9 +159,9 @@ def draw_pathcollection(data, obj):
marker0 = None
for marker, path in paths.items():
if (
numpy.array_equal(path.codes, p.codes)
np.array_equal(path.codes, p.codes)
and (path.vertices.shape == p.vertices.shape)
and numpy.max(numpy.abs(path.vertices - p.vertices)) < 1.0e-10
and np.max(np.abs(path.vertices - p.vertices)) < 1.0e-10
):
marker0 = marker
break
Expand Down Expand Up @@ -197,8 +197,8 @@ def draw_pathcollection(data, obj):
if len(obj.get_sizes()) == len(dd):
# See Pgfplots manual, chapter 4.25.
# In Pgfplots, \mark size specifies raddi, in matplotlib circle areas.
radii = numpy.sqrt(obj.get_sizes() / numpy.pi)
dd = numpy.column_stack([dd, radii])
radii = np.sqrt(obj.get_sizes() / np.pi)
dd = np.column_stack([dd, radii])
labels.append("sizedata" + 14 * " ")
draw_options.extend(
[
Expand Down Expand Up @@ -298,7 +298,7 @@ def get_draw_options(data, obj, ec, fc, ls, lw, hatch=None):
if ec is None or ec_rgba[3] == 0.0:
# Assuming that a hatch marker indicates that hatches are wanted, also
# when the edge color is (0, 0, 0, 0), i.e., the edge is invisible
h_col, h_rgba = "black", numpy.array([0, 0, 0, 1])
h_col, h_rgba = "black", np.array([0, 0, 0, 1])
else:
h_col, h_rgba = ec_col, ec_rgba
else:
Expand Down
Loading