tikzplot42 0.6.3__tar.gz → 0.6.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/PKG-INFO +2 -1
  2. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/pyproject.toml +2 -2
  3. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/axes.py +158 -73
  4. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/axes.pyi +103 -40
  5. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/axes3d.py +2 -2
  6. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/colorbar.py +4 -4
  7. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/colors.py +4 -4
  8. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/elements.py +13 -4
  9. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/figure.py +8 -5
  10. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/figure.pyi +138 -9
  11. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/plots.py +12 -3
  12. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/plots.pyi +219 -38
  13. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot42.egg-info/PKG-INFO +2 -1
  14. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot42.egg-info/requires.txt +1 -0
  15. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test16.py +1 -1
  16. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test5.py +1 -1
  17. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/LICENSE +0 -0
  18. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/README.md +0 -0
  19. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/setup.cfg +0 -0
  20. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/__init__.py +0 -0
  21. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/__init__.pyi +0 -0
  22. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/arrows.py +0 -0
  23. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/axes3d.pyi +0 -0
  24. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/border_finder.py +0 -0
  25. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/colorbar.pyi +0 -0
  26. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/config.py +0 -0
  27. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/config.pyi +0 -0
  28. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/elements.pyi +0 -0
  29. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/latex_special.py +0 -0
  30. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/pie.py +0 -0
  31. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/py.typed +0 -0
  32. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/state.py +0 -0
  33. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/styles.py +0 -0
  34. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/styles.pyi +0 -0
  35. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot/texts.py +0 -0
  36. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot42.egg-info/SOURCES.txt +0 -0
  37. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot42.egg-info/dependency_links.txt +0 -0
  38. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/src/tikzplot42.egg-info/top_level.txt +0 -0
  39. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test1.py +0 -0
  40. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test10.py +0 -0
  41. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test11.py +0 -0
  42. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test12.py +0 -0
  43. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test13.py +0 -0
  44. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test14.py +0 -0
  45. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test15.py +0 -0
  46. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test17.py +0 -0
  47. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test18.py +0 -0
  48. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test19.py +0 -0
  49. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test2.py +0 -0
  50. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test20.py +0 -0
  51. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test21.py +0 -0
  52. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test22.py +0 -0
  53. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test23.py +0 -0
  54. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test24.py +0 -0
  55. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test25.py +0 -0
  56. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test26.py +0 -0
  57. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test27.py +0 -0
  58. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test28.py +0 -0
  59. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test3.py +0 -0
  60. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test4.py +0 -0
  61. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test6.py +0 -0
  62. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test7.py +0 -0
  63. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test8.py +0 -0
  64. {tikzplot42-0.6.3 → tikzplot42-0.6.5}/tests/test9.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tikzplot42
3
- Version: 0.6.3
3
+ Version: 0.6.5
4
4
  Summary: TikzPlot to make TikZ/PGFPlots plots with matplotlib.pyplot-like syntax.
5
5
  Author-email: Zan Ambrozic <zan.ambrozic7@gmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -696,6 +696,7 @@ License-File: LICENSE
696
696
  Requires-Dist: numpy
697
697
  Requires-Dist: matplotlib
698
698
  Requires-Dist: scipy
699
+ Requires-Dist: scikit-image
699
700
  Dynamic: license-file
700
701
 
701
702
  # TikzPlot
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tikzplot42"
7
- version = "0.6.3"
7
+ version = "0.6.5"
8
8
  description = "TikzPlot to make TikZ/PGFPlots plots with matplotlib.pyplot-like syntax."
9
9
  authors = [
10
10
  { name = "Zan Ambrozic", email = "zan.ambrozic7@gmail.com" }
@@ -23,7 +23,7 @@ classifiers = [
23
23
  "Programming Language :: Python :: 3.14",
24
24
  "Topic :: Scientific/Engineering :: Visualization",
25
25
  ]
26
- dependencies = ["numpy", "matplotlib", "scipy"]
26
+ dependencies = ["numpy", "matplotlib", "scipy", "scikit-image"]
27
27
 
28
28
  [project.urls]
29
29
  Homepage = "https://github.com/ZanAmb/TikzPlot"
@@ -1,5 +1,3 @@
1
- from math import isqrt
2
- from turtle import pos
3
1
  from typing import Any, Iterable, Tuple
4
2
  import copy
5
3
 
@@ -539,6 +537,7 @@ class BaseAxes:
539
537
  else:
540
538
  lines[0].append(list(zip(x_seg, y_seg)))
541
539
  ol = None
540
+ settings["empty line"] = "jump"
542
541
  if cmap is not None:
543
542
  vmin = 0
544
543
  vmax = _np.max(_np.hypot(u, v))
@@ -547,7 +546,6 @@ class BaseAxes:
547
546
  self._get_free_overlay(cb=cb)
548
547
  ol = self._get_overlay()
549
548
  self._cmap_bar[ol] = cb
550
- settings["empty line"] = "jump"
551
549
  settings["mesh"] = None
552
550
  settings["point meta"] = "explicit"
553
551
  st["color"] = True
@@ -592,7 +590,7 @@ class BaseAxes:
592
590
  arrow_u.append(pu / p_norm)
593
591
  arrow_v.append(pv / p_norm)
594
592
  arrow_c.append(p_norm)
595
- sc = 1e-5 * max(domain_dx, domain_dy) / _np.max(_np.hypot(u, v))
593
+ sc = 1e-2 * max(domain_dx, domain_dy)
596
594
  if len(arrow_x) > 0:
597
595
  if cmap is not None:
598
596
  self.quiver(_np.array(arrow_x), _np.array(arrow_y), _np.array(arrow_u), _np.array(arrow_v), _np.array(arrow_c), scale=sc, pivot="middle", lw=arrowsize/2, cmap=cmap, vmin=0, vmax=_np.max(_np.hypot(u, v)))
@@ -644,9 +642,9 @@ class BaseAxes:
644
642
  if "colors" in kwargs:
645
643
  colors = kwargs.pop("colors")
646
644
  if isinstance(colors, list):
647
- trgts = None if _np.isclose(_np.min(_np.diff(levels)), _np.max(_np.diff(levels))) else levels
645
+ #trgts = None if _np.isclose(_np.min(_np.diff(levels)), _np.max(_np.diff(levels))) else levels
648
646
  kwargs["cmap"] = colors
649
- cb = Colorbar(cmap=colors, lower=vmin, upper=vmax, targets=trgts)
647
+ cb = Colorbar(cmap=colors, lower=vmin, upper=vmax, targets=levels)
650
648
  else:
651
649
  cb = None
652
650
  kwargs["color"] = colors
@@ -1332,7 +1330,7 @@ class BaseAxes:
1332
1330
  overlay = self._get_free_overlay()
1333
1331
  self._overlay_special[overlay] = {"stack plots": "y", "area style": None}
1334
1332
  if base_set != "zero":
1335
- self._plot(x, baseline, overlay=overlay, alpha=0)
1333
+ self._plot(x, baseline, overlay=overlay, alpha=0, settings={"stackplot": {}})
1336
1334
  datas = {}
1337
1335
  for kw in ["labels", "colors", "alpha", "facecolor", "fc", "edgecolor", "ec", "linewidth", "lw", "linestyle", "ls", "hatch", "hatch_color", "hatch_linewidth", "hatch_distance"]:
1338
1336
  if kw in kwargs:
@@ -1352,7 +1350,7 @@ class BaseAxes:
1352
1350
  for i in range(len(y)):
1353
1351
  kws = {kw: datas[kw][i] for kw in datas}
1354
1352
  kws["_endnotes"] = r"\closedcycle"
1355
- output.append(self._plot(x, y[i], overlay=overlay, settings={"fill": None}, **kws))
1353
+ output.append(self._plot(x, y[i], overlay=overlay, settings={"fill": None, "stackplot": {}}, **kws))
1356
1354
  return output
1357
1355
 
1358
1356
  def step(self, x, y, *args, **kwargs):
@@ -1800,32 +1798,34 @@ class BaseAxes:
1800
1798
  if "base" in kwargs:
1801
1799
  self._axis_options["log basis y"] = kwargs["base"]
1802
1800
 
1803
- def set_yticks(self, *ticks, labels=None, **kwargs):
1801
+ def set_yticks(self, *ticks, labels=None, scaled=None, **kwargs):
1804
1802
  pass_to_labels = {"rotation", "va", "verticalalignment", "ha", "horizontalalignment"}
1805
1803
  kws = {"color", "c", "fontsize"} | pass_to_labels
1806
1804
  kwargs = self._check_kwargs("set_yticks", kws, **kwargs)
1807
1805
  st = {}
1806
+ if scaled is not None:
1807
+ self._axis_options["scaled y ticks"] = "true" if scaled else "false"
1808
1808
  if "color" in kwargs or "c" in kwargs:
1809
1809
  c = kwargs.get("color", kwargs.get("c", None))
1810
1810
  st["text"] = self._match_color(c)
1811
1811
  if "fontsize" in kwargs:
1812
1812
  st["font"] = self._tex_fontsize(kwargs["fontsize"])
1813
1813
  if st:
1814
- self._update_axis_options("y tick style", st)
1814
+ self._update_axis_options("y tick label style", st)
1815
1815
  passing = {k: kwargs[k] for k in pass_to_labels if k in kwargs}
1816
1816
  if passing:
1817
1817
  self.set_yticklabels(**passing)
1818
1818
  if ticks:
1819
1819
  if len(ticks) == 2:
1820
1820
  ticks, labels = ticks
1821
- elif len(ticks) == 1 and isinstance(ticks[0], (list, tuple)):
1822
- ticks = ticks[0]
1821
+ elif len(ticks) == 1 and isinstance(ticks[0], Iterable):
1822
+ ticks = list(ticks[0])
1823
1823
  else: raise Warning("Too many positional arguments for set_xticks. Expected 1 or 2.")
1824
1824
  if list(ticks) != []:
1825
1825
  s_ticks = map(str, ticks)
1826
1826
  self._axis_options["ytick"]=f"{{{','.join(s_ticks)}}}"
1827
1827
  if labels is not None and len(labels)==len(ticks):
1828
- self._axis_options["yticklabels"]=f"{{{tex_text(','.join (labels))}}}"
1828
+ self._axis_options["yticklabels"]=f"{{{tex_text(','.join(labels))}}}"
1829
1829
  elif labels is not None and len(labels) == 0:
1830
1830
  self._axis_options["yticklabels"]=r"{}"
1831
1831
  self._yticks = False
@@ -1870,13 +1870,14 @@ class BaseAxes:
1870
1870
  elif ha != "center":
1871
1871
  raise Warning(f"Invalid horizontalalignment: {ha}. Must be one of 'left', 'right', or 'center'.")
1872
1872
  if st:
1873
- self._update_axis_options("y tick style", st)
1873
+ self._update_axis_options("y tick label style", st)
1874
1874
  if list(labels) != []:
1875
1875
  if len(labels) == 1 and isinstance(labels[0], (list, tuple)):
1876
1876
  if len(labels[0]) > 0:
1877
1877
  self._axis_options["yticklabels"]=f"{{{tex_text(','.join(labels[0]))}}}"
1878
1878
  else:
1879
1879
  self._axis_options["yticklabels"]=r"{}"
1880
+ self._axis_options["scaled y ticks"]="false"
1880
1881
  self._yticks = False
1881
1882
 
1882
1883
  def set_xlabel(self, label, **kwargs):
@@ -2021,12 +2022,14 @@ class BaseAxes:
2021
2022
  if "base" in kwargs:
2022
2023
  self._axis_options["log basis x"] = kwargs["base"]
2023
2024
 
2024
- def set_xticks(self, *ticks, labels=None, **kwargs):
2025
+ def set_xticks(self, *ticks, labels=None, scaled=None, **kwargs):
2025
2026
  if isinstance(self, Secondary):
2026
2027
  return self._primary.set_xticks(*ticks, labels=labels, **kwargs)
2027
2028
  pass_to_labels = {"rotation", "ha", "horizontalalignment", "va", "verticalalignment"}
2028
2029
  kws = {"color", "c", "fontsize"} | pass_to_labels
2029
2030
  kwargs = self._check_kwargs("set_xticks", kws, **kwargs)
2031
+ if scaled is not None:
2032
+ self._axis_options["scaled x ticks"] = "true" if scaled else "false"
2030
2033
  st = {}
2031
2034
  if "color" in kwargs or "c" in kwargs:
2032
2035
  c = kwargs.get("color", kwargs.get("c", None))
@@ -2041,8 +2044,8 @@ class BaseAxes:
2041
2044
  if ticks:
2042
2045
  if len(ticks) == 2:
2043
2046
  ticks, labels = ticks
2044
- elif len(ticks) == 1 and isinstance(ticks[0], (list, tuple)):
2045
- ticks = ticks[0]
2047
+ elif len(ticks) == 1 and isinstance(ticks[0], Iterable):
2048
+ ticks = list(ticks[0])
2046
2049
  else: raise Warning("Too many positional arguments for set_xticks. Expected 1 or 2.")
2047
2050
  if list(ticks) != []:
2048
2051
  s_ticks = map(str, ticks)
@@ -2102,9 +2105,9 @@ class BaseAxes:
2102
2105
  self._axis_options["xticklabels"]=f"{{{tex_text(','.join(labels[0]))}}}"
2103
2106
  else:
2104
2107
  self._axis_options["xticklabels"]=r"{}"
2108
+ self._axis_options["scaled x ticks"]="false"
2105
2109
  self._xticks = False
2106
2110
 
2107
-
2108
2111
  def tick_params(self, axis="both", **kwargs):
2109
2112
  kws = {"color", "c", "labelsize", "labelcolor", "colors", "direction", "top", "bottom", "left", "right", "labelbottom", "labelleft"}
2110
2113
  kwargs = self._check_kwargs("tick_params", kws, **kwargs)
@@ -2174,7 +2177,7 @@ class BaseAxes:
2174
2177
  elif self._axis_options["ytick pos"] == "none":
2175
2178
  self._update_axis_options("ytick style", {"draw": self._axis_options.pop("ytick pos")})
2176
2179
 
2177
- _LEGEND_LOC_MAP = ["best", "upper right", "upper left", "lower_left", "lower right", "right", "center left", "center right", "lower center", "upper center", "center"]
2180
+ _LEGEND_LOC_MAP = ["best", "upper right", "upper left", "lower left", "lower right", "right", "center left", "center right", "lower center", "upper center", "center"]
2178
2181
  _ANCHOR_MAP = {"top": "north", "bottom": "south", "upper": "north", "lower": "south", "left": "west", "right": "east", "center": "center"}
2179
2182
  _FONT_SIZE_MAP = {"xx-small": "tiny", "x-small": "scriptsize", "small": "footnotesize", "medium": "small", "large": "normalsize", "x-large": "large", "xx-large": "Large"}
2180
2183
 
@@ -2550,7 +2553,7 @@ class BaseAxes:
2550
2553
  kws = {"alpha", "color", "c", "fontsize", "on_top", "size", "backgroundcolor", "horizontalalignment", "ha", "verticalalignment", "va", "rotation", "label"}
2551
2554
  kwargs = self._check_kwargs("text", kws, **kwargs)
2552
2555
  if "fontsize" in kwargs or "size" in kwargs:
2553
- kwargs["fontsize"] = kwargs.pop("size", kwargs.pop("fontsize"))
2556
+ kwargs["fontsize"] = self._tex_fontsize(kwargs.pop("size", kwargs.pop("fontsize")))
2554
2557
  on_top = kwargs.pop("on_top", True)
2555
2558
  if on_top:
2556
2559
  assert self._fig is not None
@@ -2711,14 +2714,6 @@ class BaseAxes:
2711
2714
  for e in self._get_all_elements():
2712
2715
  e._filter(which, value)
2713
2716
 
2714
- def _num_points(self):
2715
- return [e._num_points() for e in self._get_all_elements()]
2716
-
2717
- def _reduce_points(self, limit):
2718
- for e in self._get_all_elements():
2719
- if e._num_points() > 0:
2720
- e._reduce_points(limit)
2721
-
2722
2717
  def _add_col(self, r,g,b):
2723
2718
  assert self._fig is not None
2724
2719
  self._fig._add_col(r,g,b)
@@ -3103,10 +3098,15 @@ class Axes(BaseAxes):
3103
3098
  self._elements[0].insert(0, Graph(self, f"graphics [xmin={xm}, xmax={xM}, ymin={ym}, ymax={yM}] {{{im_name}}}", settings={}, xerr=None, yerr=None, onlayer="axis background"))
3104
3099
  if self._hidable and self._get_all_elements() == [] and self._secondary_y is None:
3105
3100
  self._axis_options["hide axis"] = None
3106
- axis_opt_str = ""
3107
- auxiliary_opt_str = ""
3101
+ axis_opt_str: dict[int, str] = {0: "", 1: "", 2: "", 3: ""} # 0 - lower, 1 - any, 2 - top, 3 - single
3102
+ def _add_to_ax_opt(which: int|Iterable[int], entry:str):
3103
+ if isinstance(which, int):
3104
+ axis_opt_str[which] += entry
3105
+ else:
3106
+ for i in which:
3107
+ axis_opt_str[i] += entry
3108
3108
  if TikzConfig.SCHOOL_AXIS:
3109
- axis_opt_str += f",\n axis lines=middle,\n xlabel style={{at={{(ticklabel* cs:{1+TikzConfig.SCHOOL_AXIS_LABEL_MARGIN})}},anchor=north}},\n ylabel style={{at={{(ticklabel* cs:{1+TikzConfig.SCHOOL_AXIS_LABEL_MARGIN})}},anchor=east}}"
3109
+ axis_opt_str[1] += f",\n axis lines=middle,\n xlabel style={{at={{(ticklabel* cs:{1+TikzConfig.SCHOOL_AXIS_LABEL_MARGIN})}},anchor=north}},\n ylabel style={{at={{(ticklabel* cs:{1+TikzConfig.SCHOOL_AXIS_LABEL_MARGIN})}},anchor=east}}"
3110
3110
  if ("xmin" in self._axis_options and self._axis_options["xmin"] == 0) or ("xmax" in self._axis_options and self._axis_options["xmax"] == 0):
3111
3111
  self._axis_options["extra x ticks"] = r"{0}"
3112
3112
  if ("ymin" in self._axis_options and self._axis_options["ymin"] == 0) or ("ymax" in self._axis_options and self._axis_options["ymax"] == 0):
@@ -3115,16 +3115,16 @@ class Axes(BaseAxes):
3115
3115
  if "set layers" in self._axis_args:
3116
3116
  self._axis_args.remove("set layers")
3117
3117
  if TikzConfig.SCHOOL_AXIS:
3118
- axis_opt_str += f",\n set layers,\n axis line style={{on layer=axis foreground}}"
3119
- auxiliary_opt_str += ",\n set layers"
3118
+ axis_opt_str[2] += f",\n set layers,\n axis line style={{on layer=axis foreground}}"
3119
+ _add_to_ax_opt((0,1), ",\n set layers")
3120
3120
  else:
3121
3121
  if self._get_all_elements() != []:
3122
- axis_opt_str += f",\nset layers=standard, cell picture=true, grid style={{on layer=axis grid}}"
3123
- auxiliary_opt_str += "set layers=standard"
3122
+ axis_opt_str[2] += f",\nset layers=standard, cell picture=true, grid style={{on layer=axis grid}}"
3123
+ _add_to_ax_opt((0,1), "set layers=standard")
3124
3124
  if self._axis_args and not (self._hidable and self._get_all_elements() == [] and self._secondary_y is None):
3125
- axis_opt_str = ",\n".join(self._axis_args) + axis_opt_str
3125
+ axis_opt_str[2] = ",\n".join(self._axis_args) + axis_opt_str[2]
3126
3126
  if "set layers" in self._axis_args:
3127
- auxiliary_opt_str += ",\n set layers"
3127
+ _add_to_ax_opt((0,1), ",\n set layers")
3128
3128
  if self._ext_xmin or self._ext_xmax:
3129
3129
  lower = self._get_range("xmin")
3130
3130
  upper = self._get_range("xmax")
@@ -3156,16 +3156,24 @@ class Axes(BaseAxes):
3156
3156
  if self._int_ymax is not None and (upper[0] is None or upper[0] <= self._int_ymax):
3157
3157
  self._axis_options["ymax"] = self._int_ymax
3158
3158
  if self._axis_options:
3159
- if axis_opt_str: axis_opt_str += ",\n"
3160
- if auxiliary_opt_str: auxiliary_opt_str += ",\n"
3159
+ axis_opt_str[3] = axis_opt_str[2]
3160
+ for k in axis_opt_str:
3161
+ if axis_opt_str[k] and not axis_opt_str[k].endswith(",\n"):
3162
+ axis_opt_str[k] += ",\n"
3161
3163
  for k, v in self._axis_options.items():
3162
3164
  if v != {}:
3163
3165
  entry = self._parse_entry(k,v)
3164
- axis_opt_str += entry + ",\n"
3166
+ axis_opt_str[3] += entry + ",\n"
3167
+ to_back = ["grid"]
3168
+ if any(q in k for q in to_back):
3169
+ axis_opt_str[0] += entry + ",\n"
3170
+ else:
3171
+ axis_opt_str[2] += entry + ",\n"
3165
3172
  if k in ["xmin", "xmax", "ymin", "ymax", "xmode", "ymode", "log basis x", "log basis y", "width", "height", "at"]:
3166
- auxiliary_opt_str += entry + ",\n"
3167
- axis_opt_str = axis_opt_str.removesuffix(",,\n")
3168
- auxiliary_opt_str = auxiliary_opt_str.removesuffix(",,\n")
3173
+ _add_to_ax_opt((0,1), entry + ",\n")
3174
+ axis_opt_str[0] += "axis line style={draw=none},\n tick style={draw=none},\n minor tick style={draw=none},\n xticklabels={},\n yticklabels={},\n"
3175
+ for k in axis_opt_str:
3176
+ axis_opt_str[k] = axis_opt_str[k].removesuffix(",,\n").strip("\n")
3169
3177
  adds = {}
3170
3178
  for c in self._elements.keys():
3171
3179
  adds[c] = ""
@@ -3175,7 +3183,8 @@ class Axes(BaseAxes):
3175
3183
  cm = self._cmap_bar[c]
3176
3184
  assert isinstance(cm, Colorbar)
3177
3185
  adds[c] += f"colormap={cm._generate_tex_colormap(cm._cmap)},\n"
3178
- return axis_opt_str, "hide axis,\n" + auxiliary_opt_str, alias, adds
3186
+ axis_opt_str[1] = "hide axis,\n" + axis_opt_str[1]
3187
+ return axis_opt_str, alias, adds
3179
3188
 
3180
3189
  def _parse_entry(self, k, v):
3181
3190
  if v is None:
@@ -3200,12 +3209,16 @@ class Axes(BaseAxes):
3200
3209
  self._virtual = True
3201
3210
  from .border_finder import _get_sizes
3202
3211
  self._ext_xmin = self._ext_xmax = self._ext_ymin = self._ext_ymax = True
3203
- main, aux, alias, adds = self._axis_option_string()
3204
- if 0 in adds:
3212
+ main, alias, adds = self._axis_option_string()
3213
+ aux = main[1]
3214
+ main = main[2]
3215
+ if not self._fig._tight_params.get("ignore_colorbars", False) and 0 in adds:
3205
3216
  main += adds[0]
3206
3217
  main = r"""\begin{axis}[""" + main + r"]" + r"\end{axis}" + "\n"
3207
3218
  if self._secondary_y is not None:
3208
- main2, aux2 = self._secondary_y._axis_option_string()
3219
+ main2 = self._secondary_y._axis_option_string()
3220
+ aux2 = main2[1]
3221
+ main2 = main2[2]
3209
3222
  main2 = r"""\begin{axis}[""" + main2 + r"]" + r"\end{axis}" + "\n"
3210
3223
  main += main2
3211
3224
  for k in adds:
@@ -3283,12 +3296,18 @@ class Axes(BaseAxes):
3283
3296
  self._fig._add_required_package("\\usepgfplotslibrary{polar}")
3284
3297
  elif self._projection == "smith":
3285
3298
  self._fig._add_required_package("\\usepgfplotslibrary{smithchart}")
3286
- main_ax, aux_ax, alias, adds = self._axis_option_string()
3299
+ ax_opt, alias, adds = self._axis_option_string()
3300
+ aux_ax = ax_opt[1]
3301
+ if len (self._elements) <= 1:
3302
+ main_ax = ax_opt[3]
3303
+ else:
3304
+ main_ax = ax_opt[2]
3287
3305
  contents = self._content_tex(filename)
3288
3306
  if self._extend is not None:
3289
3307
  lines.append(f"\\nextgroupplot[alias={alias}, width={self._extend[0]}cm, height={self._extend[1]}cm, hide axis]")
3290
3308
  for i in self._elements.keys():
3291
- spec = ",\n".join([self._parse_entry(k, v) for k, v in self._overlay_special.get(i, {}).items()]) + ",\n" if i in self._overlay_special else ""
3309
+ spec = ",\n".join([self._parse_entry(k, v) for k, v in self._overlay_special.get(i, {}).items()]) + "," if i in self._overlay_special else ""
3310
+ spec = spec.strip("\n")
3292
3311
  if self._projection == "polar":
3293
3312
  lines2.append("\\begin{polaraxis}["+ f"\n at={{({alias}.south west)}},")
3294
3313
  elif self._projection == "smith":
@@ -3298,9 +3317,18 @@ class Axes(BaseAxes):
3298
3317
  if TikzConfig.SCALE_ONLY_AXIS:
3299
3318
  lines2.append("scale only axis,")
3300
3319
  if i == self._get_overlay():
3301
- lines2.append(f"{main_ax}{spec}\n]")
3320
+ if i in adds and adds[i] != "":
3321
+ addit = adds[i]
3322
+ addit = addit.replace(f"at={{({alias}", f"at={{({alias}a")
3323
+ addit = f"alias={alias}a,\n" + addit
3324
+ lines2.append(f"{main_ax}{spec+addit}\n]")
3325
+ else:
3326
+ lines2.append(f"{main_ax}{spec}\n]")
3302
3327
  else:
3303
- lines2.append(f"{aux_ax}{spec}\n]")
3328
+ if i == 0:
3329
+ lines2.append(f"{ax_opt[0]}{spec}\n]")
3330
+ else:
3331
+ lines2.append(f"{aux_ax}{spec}\n]")
3304
3332
  lines2.append(contents[i])
3305
3333
  if i == self._get_overlay() and self._overlay_legend:
3306
3334
  lines2 += self._overlay_legend_entries
@@ -3314,19 +3342,28 @@ class Axes(BaseAxes):
3314
3342
  else:
3315
3343
  lines2.append("\\end{axis}")
3316
3344
  if self._secondary_y is not None:
3317
- main_ax2, aux_ax2 = self._secondary_y._axis_option_string()
3345
+ ax_opt2 = self._secondary_y._axis_option_string()
3346
+ aux_ax2 = ax_opt2[1]
3347
+ if len (self._secondary_y._elements) <= 1:
3348
+ main_ax2 = ax_opt2[3]
3349
+ else:
3350
+ main_ax2 = ax_opt2[2]
3318
3351
  contents2 = self._secondary_y._content_tex(filename)
3319
3352
  for i in self._secondary_y._elements.keys():
3320
3353
  lines2.append("\\begin{axis}[")
3321
3354
  if TikzConfig.SCALE_ONLY_AXIS:
3322
3355
  lines2.append("scale only axis,")
3323
- spec = ",\n".join([self._parse_entry(k, v) for k, v in self._secondary_y._overlay_special.get(i, {}).items()]) + ",\n" if i in self._secondary_y._overlay_special else ""
3356
+ spec = ",\n".join([self._parse_entry(k, v) for k, v in self._secondary_y._overlay_special.get(i, {}).items()]) + "," if i in self._secondary_y._overlay_special else ""
3324
3357
  if i in adds:
3325
3358
  spec += adds[i]
3359
+ spec = spec.strip("\n")
3326
3360
  if i == sorted(self._secondary_y._elements.keys())[-1]:
3327
3361
  lines2.append(f"{main_ax2}{spec}\n]")
3328
3362
  else:
3329
- lines2.append(f"{aux_ax2}{spec}\n]")
3363
+ if i == 0:
3364
+ lines2.append(f"{ax_opt2[0]}{spec}\n]")
3365
+ else:
3366
+ lines2.append(f"{aux_ax2}{spec}\n]")
3330
3367
  lines2.append(contents2[i])
3331
3368
  if i == sorted(self._secondary_y._elements.keys())[-1]:
3332
3369
  lines2 += self._secondary_y._overlay_legend_entries
@@ -3337,9 +3374,10 @@ class Axes(BaseAxes):
3337
3374
  elif self._projection in ["polar", "smith"] and TikzConfig.USE_GROUPPLOTS and not single:
3338
3375
  lines.append(f"\\nextgroupplot[alias={alias}, width={self._width}, height={self._height}, hide axis]")
3339
3376
  for i in self._elements.keys():
3340
- spec = ",\n".join([self._parse_entry(k, v) for k, v in self._overlay_special.get(i, {}).items()]) + ",\n" if i in self._overlay_special else ""
3377
+ spec = ",\n".join([self._parse_entry(k, v) for k, v in self._overlay_special.get(i, {}).items()]) + "," if i in self._overlay_special else ""
3341
3378
  if i in adds:
3342
3379
  spec += adds[i]
3380
+ spec = spec.strip("\n")
3343
3381
  if self._projection == "polar":
3344
3382
  lines2.append("\\begin{polaraxis}["+ f"\n at={{({alias}.south west)}},")
3345
3383
  elif self._projection == "smith":
@@ -3371,28 +3409,31 @@ class Axes(BaseAxes):
3371
3409
  if TikzConfig.SCALE_ONLY_AXIS:
3372
3410
  lines.append("scale only axis,")
3373
3411
  if self._get_overlay() == 0:
3374
- spec = ",\n".join([self._parse_entry(k, v) for k, v in self._overlay_special.get(0, {}).items()]) + ",\n" if 0 in self._overlay_special else ""
3412
+ spec = ",\n".join([self._parse_entry(k, v) for k, v in self._overlay_special.get(0, {}).items()]) + "," if 0 in self._overlay_special else ""
3375
3413
  if 0 in adds:
3376
3414
  spec += adds[0]
3415
+ spec = spec.strip("\n")
3377
3416
  if self._secondary_y is not None or any([c is not None for c in self._colorbar.values()]) or self._externs:
3378
3417
  lines.append(f"{main_ax}{spec}alias={alias}\n]")
3379
3418
  else:
3380
3419
  lines.append(f"{main_ax}{spec}\n]")
3381
3420
  lines.append(contents[0])
3382
3421
  else:
3383
- spec = ",\n".join([self._parse_entry(k, v) for k, v in self._overlay_special.get(0, {}).items()]) + ",\n" if 0 in self._overlay_special else ""
3422
+ spec = ",\n".join([self._parse_entry(k, v) for k, v in self._overlay_special.get(0, {}).items()]) + "," if 0 in self._overlay_special else ""
3384
3423
  if 0 in adds:
3385
3424
  spec += adds[0]
3425
+ spec = spec.strip("\n")
3386
3426
  if len(contents[0]) == 0:
3387
- lines.append(f"{aux_ax}{spec}alias={alias}\n]".replace("set layers=standard,\n", ""))
3427
+ lines.append(f"{ax_opt[0]}{spec}alias={alias}\n]".replace("set layers=standard,\n", ""))
3388
3428
  else:
3389
- lines.append(f"{aux_ax}{spec}alias={alias}\n]")
3429
+ lines.append(f"{ax_opt[0]}{spec}alias={alias}\n]")
3390
3430
  lines.append(contents[0])
3391
3431
  for i in self._elements.keys():
3392
3432
  if i == 0: continue
3393
- spec = ",\n".join([self._parse_entry(k, v) for k, v in self._overlay_special.get(i, {}).items()]) + ",\n" if i in self._overlay_special else ""
3433
+ spec = ",\n".join([self._parse_entry(k, v) for k, v in self._overlay_special.get(i, {}).items()]) + "," if i in self._overlay_special else ""
3394
3434
  if i in adds:
3395
3435
  spec += adds[i]
3436
+ spec = spec.strip("\n")
3396
3437
  lines2.append("\\begin{axis}[")
3397
3438
  if TikzConfig.SCALE_ONLY_AXIS:
3398
3439
  lines2.append("scale only axis,")
@@ -3420,17 +3461,26 @@ class Axes(BaseAxes):
3420
3461
  elif not TikzConfig.USE_GROUPPLOTS or (TikzConfig.USE_GROUPPLOTS and single):
3421
3462
  lines.append("\\end{axis}")
3422
3463
  if self._secondary_y is not None:
3423
- main_ax2, aux_ax2 = self._secondary_y._axis_option_string()
3464
+ ax_opt2 = self._secondary_y._axis_option_string()
3465
+ aux_ax2 = ax_opt2[1]
3466
+ if len (self._secondary_y._elements) <= 1:
3467
+ main_ax2 = ax_opt2[3]
3468
+ else:
3469
+ main_ax2 = ax_opt2[2]
3424
3470
  contents2 = self._secondary_y._content_tex(filename)
3425
3471
  for i in self._secondary_y._elements.keys():
3426
3472
  lines2.append("\\begin{axis}[")
3427
3473
  if TikzConfig.SCALE_ONLY_AXIS:
3428
3474
  lines2.append("scale only axis,")
3429
- spec = ",\n".join([self._parse_entry(k, v) for k, v in self._secondary_y._overlay_special.get(i, {}).items()]) + ",\n" if i in self._secondary_y._overlay_special else ""
3475
+ spec = ",\n".join([self._parse_entry(k, v) for k, v in self._secondary_y._overlay_special.get(i, {}).items()]) + "," if i in self._secondary_y._overlay_special else ""
3476
+ spec = spec.strip("\n")
3430
3477
  if i == sorted(self._secondary_y._elements.keys())[-1]:
3431
3478
  lines2.append(f"{main_ax2}{spec}\n]")
3432
3479
  else:
3433
- lines2.append(f"{aux_ax2}{spec}\n]")
3480
+ if i == 0:
3481
+ lines2.append(f"{ax_opt2[0]}{spec}\n]")
3482
+ else:
3483
+ lines2.append(f"{aux_ax2}{spec}\n]")
3434
3484
  lines2.append(contents2[i])
3435
3485
  if i == sorted(self._secondary_y._elements.keys())[-1]:
3436
3486
  lines2 += self._secondary_y._overlay_legend_entries
@@ -3463,6 +3513,18 @@ class Axes(BaseAxes):
3463
3513
  if position not in ["above", "below", "left", "right"]:
3464
3514
  raise ValueError(f"Invalid position: {position}. Must be one of 'above', 'below', 'left', or 'right'.")
3465
3515
  return self._fig._inset(self, position, relsize=relsize, sharex=sharex, sharey=sharey)
3516
+
3517
+ def _num_points(self):
3518
+ if self._secondary_y is not None:
3519
+ return [e._num_points() for e in self._get_all_elements()] + self._secondary_y._num_points()
3520
+ return [e._num_points() for e in self._get_all_elements()]
3521
+
3522
+ def _reduce_points(self, limit):
3523
+ for e in self._get_all_elements():
3524
+ if e._num_points() > 0:
3525
+ e._reduce_points(limit)
3526
+ if self._secondary_y is not None:
3527
+ self._secondary_y._reduce_points(limit)
3466
3528
 
3467
3529
  class Secondary(BaseAxes):
3468
3530
  def __init__(self, primary):
@@ -3489,11 +3551,10 @@ class Secondary(BaseAxes):
3489
3551
  self._axis_options["width"] = self._primary._width
3490
3552
  if self._primary._height:
3491
3553
  self._axis_options["height"] = self._primary._height
3492
- axis_opt_str = ""
3493
- auxiliary_opt_str = ""
3554
+ axis_opt_str: dict[int, str] = {0: "", 1: "", 2: "", 3: ""} # 0 - lower, 1 - any, 2 - top, 3 - single
3494
3555
  if self._axis_args:
3495
- axis_opt_str += ",\n".join(self._axis_args)
3496
- auxiliary_opt_str += ",\n".join(self._axis_args)
3556
+ for i in [1,2,3]:
3557
+ axis_opt_str[i] += ",\n".join(self._axis_args)
3497
3558
  if self._ext_ymin or self._ext_ymax:
3498
3559
  lower = self._get_range("ymin")
3499
3560
  upper = self._get_range("ymax")
@@ -3504,9 +3565,15 @@ class Secondary(BaseAxes):
3504
3565
  self._axis_options["ymax"] = self._fig._next_limname("ymax", self._axis_options.get("ymax", yM))
3505
3566
  self._axis_options["xmin"] = self._primary._axis_options["xmin"]
3506
3567
  self._axis_options["xmax"] = self._primary._axis_options["xmax"]
3568
+ if "xmode" in self._primary._axis_options:
3569
+ self._axis_options["xmode"] = self._primary._axis_options["xmode"]
3570
+ if "log basis x" in self._primary._axis_options:
3571
+ self._axis_options["log basis x"] = self._primary._axis_options["log basis x"]
3507
3572
  if self._axis_options:
3508
- if axis_opt_str: axis_opt_str += ",\n"
3509
- if auxiliary_opt_str: auxiliary_opt_str += ",\n"
3573
+ axis_opt_str[3] = axis_opt_str[2]
3574
+ for k in axis_opt_str:
3575
+ if axis_opt_str[k] and not axis_opt_str[k].endswith(",\n"):
3576
+ axis_opt_str[k] += ",\n"
3510
3577
  def parse_entry(k,v):
3511
3578
  if isinstance(v, dict):
3512
3579
  return f"{k}={{" + ",\n".join(f"{kk}={vv}" for kk, vv in v.items()) + "}"
@@ -3514,10 +3581,20 @@ class Secondary(BaseAxes):
3514
3581
  return f"{k}={v}"
3515
3582
  for k, v in self._axis_options.items():
3516
3583
  entry = parse_entry(k,v)
3517
- axis_opt_str += entry + ",\n"
3584
+ axis_opt_str[3] += entry + ",\n"
3585
+ to_back = ["grid"]
3586
+ if any(q in k for q in to_back):
3587
+ axis_opt_str[0] += entry + ",\n"
3588
+ else:
3589
+ axis_opt_str[2] += entry + ",\n"
3518
3590
  if k in ["xmin", "xmax", "ymin", "ymax", "xmode", "ymode", "log basis x", "log basis y", "width", "height", "at", "axis y line*", "axis x line", "anchor"]:
3519
- auxiliary_opt_str += entry + ",\n"
3520
- return axis_opt_str, "hide axis,\n" + auxiliary_opt_str
3591
+ axis_opt_str[0] += entry + ",\n"
3592
+ axis_opt_str[1] += entry + ",\n"
3593
+ axis_opt_str[0] += "axis line style={draw=none},\n tick style={draw=none},\n minor tick style={draw=none},\n xticklabels={},\n yticklabels={},\n"
3594
+ for k in axis_opt_str:
3595
+ axis_opt_str[k] = axis_opt_str[k].removesuffix(",,\n").strip("\n")
3596
+ axis_opt_str[1] = "hide axis,\n" + axis_opt_str[1]
3597
+ return axis_opt_str
3521
3598
 
3522
3599
  def _padding(self):
3523
3600
  return TikzConfig.SEC_Y_PADDING + TikzConfig.YTICK_PADDING * self._yticks + TikzConfig.SEC_Y_LABEL_PADDING * ("ylabel" in self._axis_options)
@@ -3526,4 +3603,12 @@ class Secondary(BaseAxes):
3526
3603
  return self._primary._get_defcol(index)
3527
3604
 
3528
3605
  def _get_index(self):
3529
- return self._primary._get_index()
3606
+ return self._primary._get_index()
3607
+
3608
+ def _num_points(self):
3609
+ return [e._num_points() for e in self._get_all_elements()]
3610
+
3611
+ def _reduce_points(self, limit):
3612
+ for e in self._get_all_elements():
3613
+ if e._num_points() > 0:
3614
+ e._reduce_points(limit)