tikzplot42 0.3.8__tar.gz → 0.4.3__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 (51) hide show
  1. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/PKG-INFO +4 -2
  2. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/README.md +3 -1
  3. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/pyproject.toml +1 -1
  4. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/axes.py +56 -25
  5. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/axes.pyi +43 -15
  6. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/axes3d.py +24 -6
  7. tikzplot42-0.4.3/src/tikzplot/axes3d.pyi +43 -0
  8. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/colorbar.py +14 -2
  9. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/colorbar.pyi +13 -13
  10. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/colors.py +7 -5
  11. tikzplot42-0.4.3/src/tikzplot/config.py +156 -0
  12. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/config.pyi +63 -4
  13. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/elements.py +38 -15
  14. tikzplot42-0.4.3/src/tikzplot/elements.pyi +92 -0
  15. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/figure.py +9 -4
  16. tikzplot42-0.4.3/src/tikzplot/figure.pyi +76 -0
  17. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/plots.py +78 -7
  18. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/plots.pyi +49 -55
  19. tikzplot42-0.4.3/src/tikzplot/py.typed +2 -0
  20. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/state.py +6 -5
  21. tikzplot42-0.4.3/src/tikzplot/styles.py +94 -0
  22. tikzplot42-0.4.3/src/tikzplot/styles.pyi +41 -0
  23. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot42.egg-info/PKG-INFO +4 -2
  24. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot42.egg-info/SOURCES.txt +6 -3
  25. tikzplot42-0.4.3/tests/test11.py +100 -0
  26. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/tests/test3.py +1 -1
  27. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/tests/test7.py +2 -2
  28. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/tests/test8.py +1 -3
  29. tikzplot42-0.4.3/tests/test_styles.py +17 -0
  30. tikzplot42-0.3.8/src/tikzplot/colors.pyi +0 -1
  31. tikzplot42-0.3.8/src/tikzplot/config.py +0 -103
  32. tikzplot42-0.3.8/src/tikzplot/elements.pyi +0 -11
  33. tikzplot42-0.3.8/src/tikzplot/figure.pyi +0 -34
  34. tikzplot42-0.3.8/src/tikzplot/py.typed +0 -0
  35. tikzplot42-0.3.8/src/tikzplot/state.pyi +0 -3
  36. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/LICENSE +0 -0
  37. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/setup.cfg +0 -0
  38. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/__init__.py +0 -0
  39. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/__init__.pyi +0 -0
  40. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/latex_special.py +0 -0
  41. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot/texts.py +0 -0
  42. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot42.egg-info/dependency_links.txt +0 -0
  43. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot42.egg-info/requires.txt +0 -0
  44. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/src/tikzplot42.egg-info/top_level.txt +0 -0
  45. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/tests/test1.py +0 -0
  46. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/tests/test10.py +0 -0
  47. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/tests/test2.py +0 -0
  48. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/tests/test4.py +0 -0
  49. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/tests/test5.py +0 -0
  50. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/tests/test6.py +0 -0
  51. {tikzplot42-0.3.8 → tikzplot42-0.4.3}/tests/test9.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tikzplot42
3
- Version: 0.3.8
3
+ Version: 0.4.3
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
@@ -765,6 +765,8 @@ If axes and plot have different name for command with same effect, both are impl
765
765
  - `ax.twinx()`,
766
766
  - `ax.set()`.
767
767
 
768
+ There is a limited support for built-in styles (e.g. `plt.style.use("default")`), you may also define your own style using `plt.style.set_profile()`. Currently supported features are: color cycle (hex colors sequence), line width (in pt), grid (with matplotlib kwargs), background (latex style key=value), additional settings (raw latex code for optional arguments to axis: key=value).
769
+
768
770
  #### Supported common **kwargs
769
771
  - `color/c` (all matplotlib formats, except color schemes which are not yet implemented),
770
772
  - `linestyle/ls`,
@@ -788,6 +790,6 @@ For plot configurations (default sizes, paddings, etc.), use `from tikzplot impo
788
790
  Currently supported parameters are listed with their default values in `src/tikzplot/config.py`.
789
791
 
790
792
  ## More features coming soon...
791
- - basic color schemes,
793
+ - more developed styles,
792
794
  - improved 3D plots (currently only basic support: plot, errorbar, fill_between, scatter, plot_wireframe, plot_surface),
793
795
  - ...
@@ -63,6 +63,8 @@ If axes and plot have different name for command with same effect, both are impl
63
63
  - `ax.twinx()`,
64
64
  - `ax.set()`.
65
65
 
66
+ There is a limited support for built-in styles (e.g. `plt.style.use("default")`), you may also define your own style using `plt.style.set_profile()`. Currently supported features are: color cycle (hex colors sequence), line width (in pt), grid (with matplotlib kwargs), background (latex style key=value), additional settings (raw latex code for optional arguments to axis: key=value).
67
+
66
68
  #### Supported common **kwargs
67
69
  - `color/c` (all matplotlib formats, except color schemes which are not yet implemented),
68
70
  - `linestyle/ls`,
@@ -86,6 +88,6 @@ For plot configurations (default sizes, paddings, etc.), use `from tikzplot impo
86
88
  Currently supported parameters are listed with their default values in `src/tikzplot/config.py`.
87
89
 
88
90
  ## More features coming soon...
89
- - basic color schemes,
91
+ - more developed styles,
90
92
  - improved 3D plots (currently only basic support: plot, errorbar, fill_between, scatter, plot_wireframe, plot_surface),
91
93
  - ...
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tikzplot42"
7
- version = "0.3.8"
7
+ version = "0.4.3"
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" }
@@ -21,15 +21,15 @@ class BaseAxes:
21
21
  else:
22
22
  self._axis_args.add(f"/pgf/number format/.cd, 1000 sep={{{TikzConfig.THOUSANDS_SEP}}}")
23
23
 
24
- self._add_legend = ""
24
+ self._add_legend = []
25
25
  self._coordinates = {}
26
26
  self._cmap_bar = None
27
27
 
28
28
  self._ext_ymin = False
29
29
  self._ext_ymax = False
30
30
 
31
- def _plot(self, x, y, settings=None, xerr=None, yerr=None, **style):
32
- if not isinstance(self, Secondary) and self._polar:
31
+ def _plot(self, x, y, settings=[], xerr=None, yerr=None, **style):
32
+ if isinstance(self, Axes) and self._polar:
33
33
  x = _np.rad2deg(x)
34
34
  e = Graph(self, (x, y), settings, xerr=xerr, yerr=yerr, **style)
35
35
  if TikzConfig.USE_GROUPPLOTS and ("axvspan" == settings or "axhspan" == settings):
@@ -71,6 +71,7 @@ class BaseAxes:
71
71
 
72
72
  try:
73
73
  c = kwargs.get("c", kwargs.get("color", None))
74
+ if c is None: raise ValueError("No color specified")
74
75
  if len(c) == len(x):
75
76
  if isinstance(c[0], (int, float)):
76
77
  if "cmap" not in kwargs:
@@ -118,9 +119,8 @@ class BaseAxes:
118
119
  x = range(len(y))
119
120
  elif len(args) == 2:
120
121
  x,y=args
121
- elif len(args) == 3:
122
- x,y,fmt=args
123
- kwargs["fmt"]=fmt
122
+ else:
123
+ raise Warning("Invalid number of args for stem.")
124
124
  if "orientation" in kwargs:
125
125
  o = kwargs.pop("orientation")
126
126
  if o == "horizontal":
@@ -139,6 +139,7 @@ class BaseAxes:
139
139
  return el._try_set_pname(pname)
140
140
  else:
141
141
  return None
142
+ assert self._fig is not None
142
143
  name1 = self._fig._get_free_path_name()
143
144
  name2 = self._fig._get_free_path_name()
144
145
  if isinstance(y1, (int, float)):
@@ -165,7 +166,7 @@ class BaseAxes:
165
166
  self._plot(xs,ys,path_name=name2, alpha=0)
166
167
  else:
167
168
  name2 = inst
168
- e = Graph(self, f"fill between [of={name1} and {name2}]",settings=None, xerr=None, yerr=None, **kwargs)
169
+ e = Graph(self, f"fill between [of={name1} and {name2}]",settings=[], xerr=None, yerr=None, **kwargs)
169
170
  self._elements.append(e)
170
171
  return e
171
172
 
@@ -224,9 +225,6 @@ class BaseAxes:
224
225
  datasets = [x]
225
226
  all_data = _np.concatenate(datasets)
226
227
  edges = _np.histogram_bin_edges(all_data, bins=bins)
227
- for data in datasets:
228
- counts, _ = _np.histogram(data, edges, density=density)
229
- centers = (edges[:-1] + edges[1:]) / 2
230
228
  widths = edges[1:] - edges[:-1]
231
229
  settings = []
232
230
  if "orientation" in kwargs and kwargs["orientation"] == "horizontal":
@@ -241,12 +239,18 @@ class BaseAxes:
241
239
  if "range" in kwargs:
242
240
  if settings[0] == "xbar":
243
241
  self.set_ylim(kwargs["range"])
244
- else:
242
+ elif isinstance(self, Axes):
245
243
  self.set_xlim(kwargs["range"])
246
- if "cumulative" in kwargs and kwargs["cumulative"]:
247
- counts = _np.cumsum(counts)
248
-
249
- return self._plot(centers, counts, settings=settings, **kwargs)
244
+ elif isinstance(self, Secondary):
245
+ self._primary.set_xlim(kwargs["range"])
246
+ outputs = []
247
+ for data in datasets:
248
+ counts, _ = _np.histogram(data, edges, density=density)
249
+ centers = (edges[:-1] + edges[1:]) / 2
250
+ if "cumulative" in kwargs and kwargs["cumulative"]:
251
+ counts = _np.cumsum(counts)
252
+ outputs.append(self._plot(centers, counts, settings=settings, **kwargs))
253
+ return outputs
250
254
 
251
255
  def step(self, x, y, *args, **kwargs):
252
256
  kws = {"fmt", "alpha", "color", "c", "linestyle", "ls", "linewidth", "lw", "marker", "markersize", "ms", "label", "where"}
@@ -358,7 +362,8 @@ class BaseAxes:
358
362
  try:
359
363
  lx,ly=float(loc[0]), float(loc[1])
360
364
  posit = "south west"
361
- except: print(f"Error parsing legend location: {loc}")
365
+ except:
366
+ print(f"Error parsing legend location: {loc}")
362
367
  else:
363
368
  if isinstance(loc, int):
364
369
  loc = self._LEGEND_LOC_MAP[loc]
@@ -379,9 +384,12 @@ class BaseAxes:
379
384
  legend_string = []
380
385
  if lx is not None and ly is not None:
381
386
  legend_string.append(r"at={(" + f"{lx},{ly}" + r")}")
382
- if len(posit):
387
+ if posit is not None and len(posit):
383
388
  legend_string.append(r"anchor=" + posit)
384
- self._axis_options["legend style"] = f"{{{','.join(legend_string)}}}"
389
+ if "legend style" in self._axis_options:
390
+ self._axis_options["legend style"] = self._axis_options["legend style"].rstrip("}") + f" ,{','.join(legend_string)}}}"
391
+ else:
392
+ self._axis_options["legend style"] = f"{{{','.join(legend_string)}}}"
385
393
  self._legend_on = True
386
394
  if "ncols" in kwargs:
387
395
  self._axis_options["legend columns"] = kwargs["ncols"]
@@ -395,10 +403,12 @@ class BaseAxes:
395
403
  for i in range(len(labs)):
396
404
  self._elements[i]._set_label(tex_text(labs[i]))
397
405
 
398
- def text(self, x, y, s, on_top=True, **kwargs):
399
- kws = {"alpha", "color", "c", "fontsize", "size", "backgroundcolor", "horizontalalignment", "ha", "verticalalignment", "va", "rotation", "label"}
406
+ def text(self, x, y, s, **kwargs):
407
+ kws = {"alpha", "color", "c", "fontsize", "on_top", "size", "backgroundcolor", "horizontalalignment", "ha", "verticalalignment", "va", "rotation", "label"}
400
408
  kwargs = self._check_kwargs("text", kws, **kwargs)
409
+ on_top = kwargs.pop("on_top", True)
401
410
  if on_top:
411
+ assert self._fig is not None
402
412
  coord = self._fig._next_coordinate_name()
403
413
  txt = Text(self, x, y, coord, s, **kwargs)
404
414
  self._fig._add_text(txt)
@@ -409,12 +419,13 @@ class BaseAxes:
409
419
  def magnify(self, x_p, y_p, x_m, y_m, zoom, size, **kwargs):
410
420
  kws = {"shape", "connect"}
411
421
  kwargs = self._check_kwargs("magnify", kws, **kwargs)
422
+ assert self._fig is not None
412
423
  n = self._fig._add_spy(zoom, size, **kwargs)
413
424
  self._coordinates.update({f"spypoint{n}": (x_p,y_p)})
414
425
  self._coordinates.update({f"spyviewr{n}": (x_m,y_m)})
415
426
 
416
427
  def _add_legend_entries(self):
417
- if self._add_legend == "": return ""
428
+ if self._add_legend == []: return ""
418
429
  axs, labs = self._add_legend
419
430
  output = ""
420
431
  if len(axs) != len(labs):
@@ -499,6 +510,7 @@ class BaseAxes:
499
510
  e._reduce_points(limit)
500
511
 
501
512
  def _add_col(self, r,g,b):
513
+ assert self._fig is not None
502
514
  self._fig._add_col(r,g,b)
503
515
 
504
516
  def set(self, **kwargs):
@@ -521,6 +533,7 @@ class Axes(BaseAxes):
521
533
  self._col = self._index - self._row * self._ncols
522
534
 
523
535
  self._fig = fig
536
+ self._style = self._fig._style
524
537
  self._imshow = None
525
538
 
526
539
  self._defcol_counter = 0
@@ -559,6 +572,18 @@ class Axes(BaseAxes):
559
572
 
560
573
  self._xticks = True
561
574
 
575
+ self._style_defaults()
576
+
577
+ def _style_defaults(self):
578
+ _gs = self._style._get_grid_cycle()
579
+ if _gs is not None:
580
+ self.grid(**_gs)
581
+ _bcgnd = self._style._get_background_cycle()
582
+ if _bcgnd is not None:
583
+ self._axis_options["axis background/.style"] = f"{{{_bcgnd}}}"
584
+ _add_settgs = self._style._get_additional_settings()
585
+ if _add_settgs is not None:
586
+ self._axis_options = _add_settgs | self._axis_options
562
587
 
563
588
  def _update_size(self):
564
589
  if self._fig._get_width():
@@ -589,7 +614,6 @@ class Axes(BaseAxes):
589
614
  #kws = {"fmt", "alpha", "color", "c", "linestyle", "ls", "linewidth", "lw", "marker", "markersize", "ms", "label"}
590
615
  #kwargs = self._check_kwargs("imshow", kws, **kwargs)
591
616
  self._imshow = (args, kwargs)
592
- #self._axis_args.add("axis on top")
593
617
  self._axis_options["enlargelimits"] = "false"
594
618
  #self._fig._add_global("\\pgfplotsset{set layers}")
595
619
  data = args[0]
@@ -630,7 +654,7 @@ class Axes(BaseAxes):
630
654
  if kwargs:
631
655
  accepted_kwargs = {"color", "c", "linestyle", "ls", "linewidth", "lw", "alpha"}
632
656
  kwargs = self._check_kwargs("grid", accepted_kwargs, **kwargs)
633
- g = Graph(self, None, None, None, None, **kwargs)._style_string()
657
+ g = Graph(self, None, [], None, None, **kwargs)._style_string()
634
658
  self._axis_options[f"{selector}grid style"] = f"{{{g}}}"
635
659
 
636
660
  def set_minorticks_num(self, num):
@@ -730,7 +754,7 @@ class Axes(BaseAxes):
730
754
  if "extent" in self._imshow[1]:
731
755
  bounds = self._imshow[1]["extent"]
732
756
  xm, xM, ym, yM = bounds
733
- self._elements.insert(0, Graph(self, f"graphics [xmin={xm}, xmax={xM}, ymin={ym}, ymax={yM}] {{{im_name}}}",settings=None, xerr=None, yerr=None, onlayer="axis background"))
757
+ self._elements.insert(0, Graph(self, f"graphics [xmin={xm}, xmax={xM}, ymin={ym}, ymax={yM}] {{{im_name}}}",settings=[], xerr=None, yerr=None, onlayer="axis background"))
734
758
  axis_opt_str = ""
735
759
  if self._axis_args:
736
760
  axis_opt_str += ",\n".join(self._axis_args)
@@ -744,7 +768,7 @@ class Axes(BaseAxes):
744
768
  if TikzConfig.SCHOOL_AXIS:
745
769
  axis_opt_str += f",\n set layers,\n axis line style={{on layer=axis foreground}}"
746
770
  else:
747
- axis_opt_str += f",\n axis on top"
771
+ axis_opt_str += f",\n set layers=standard, cell picture=true, grid style={{on layer=axis grid}}"
748
772
  if self._ext_xmin or self._ext_xmax:
749
773
  lower = self._get_range("xmin")
750
774
  upper = self._get_range("xmax")
@@ -848,6 +872,13 @@ class Secondary(BaseAxes):
848
872
  self._axis_options["y label style"] = r"{at={(" + str(TikzConfig.SEC_YLABEL_LOC[0]) + "," + str(TikzConfig.SEC_YLABEL_LOC[1]) + ")}, rotate=180}"
849
873
 
850
874
  self._fig = primary._fig
875
+ self._style = self._fig._style
876
+ self._style_defaults()
877
+
878
+ def _style_defaults(self):
879
+ _add_settgs = self._style._get_additional_settings()
880
+ if _add_settgs is not None:
881
+ self._axis_options = _add_settgs | self._axis_options
851
882
 
852
883
  def _axis_option_string(self):
853
884
  if self._primary._width:
@@ -1,9 +1,10 @@
1
1
  from typing import Any, Optional, Sequence, Tuple, Union, Literal
2
2
  import numpy as np
3
+ from pyrsistent import T
3
4
  from .colorbar import Colorbar
4
5
 
5
6
  ArrayLike = Union[Sequence[float], np.ndarray]
6
- ColorLike = Union[str, Sequence[float]]
7
+ ColorLike = Union[str, Sequence[float], Sequence[Sequence[float] | ArrayLike], np.ndarray, None]
7
8
  LineStyle = Literal["-", "--", "-.", ":", "solid", "dashed", "dashdot", "none", ""]
8
9
  MarkerStyle = Literal["o", "s", "^", "v", "x", "+", ".", "*", "None", ""]
9
10
  FontSize = Literal["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"]
@@ -48,7 +49,7 @@ class BaseAxes:
48
49
  ...
49
50
 
50
51
  def scatter(self, x: ArrayLike = ..., y: ArrayLike = ..., fmt: Optional[str] = ..., *,alpha: Optional[float] = ..., color: Optional[Union[Sequence[ColorLike], ColorLike]] = ..., c: Optional[ColorLike] = ...,
51
- marker: Optional[MarkerStyle] = ..., markersize: Optional[Union[Sequence[float], float]] = ..., s: Optional[Union[Sequence[float], float]] = ..., label:Optional[str]=..., cmap: Optional[Union[str, Colorbar]], vmin: Optional[float] = ..., vmax: Optional[float] = ...) -> None:
52
+ marker: Optional[MarkerStyle] = ..., markersize: Optional[Union[ArrayLike, float]] = ..., s: Optional[Union[ArrayLike, float]] = ..., label:Optional[str]=..., cmap: Optional[Union[str, Colorbar]], vmin: Optional[float] = ..., vmax: Optional[float] = ...) -> None:
52
53
  """
53
54
  Draw a scatter plot to the selected axis.
54
55
 
@@ -212,7 +213,7 @@ class BaseAxes:
212
213
  """
213
214
  ...
214
215
 
215
- def text(self, x: float, y: float, s: str, color: Optional[ColorLike] = ..., c: Optional[ColorLike] = ..., fontsize: Optional[FontSize] = ..., size: Optional[FontSize] = ..., backgroundcolor: Optional[ColorLike] = ..., horizontalalignment: Optional[str] = ..., ha: Optional[str] = ..., verticalalignment: Optional[str] = ..., va: Optional[str] = ..., rotation: Optional[Union[float, str]] = ..., label: Optional[str] = ...) -> None:
216
+ def text(self, x: float, y: float, s: str, color: Optional[ColorLike] = ..., c: Optional[ColorLike] = ..., fontsize: Optional[FontSize] = ..., on_top: bool = ..., size: Optional[FontSize] = ..., backgroundcolor: Optional[ColorLike] = ..., horizontalalignment: Optional[str] = ..., ha: Optional[str] = ..., verticalalignment: Optional[str] = ..., va: Optional[str] = ..., rotation: Optional[Union[float, str]] = ..., label: Optional[str] = ...) -> None:
216
217
  """
217
218
  Add text to the selected axis.
218
219
 
@@ -230,6 +231,9 @@ class BaseAxes:
230
231
  fontsize or size: FontSize, optional
231
232
  Font size
232
233
 
234
+ on_top: bool, optional
235
+ Draw text on top of other elements (True by default)
236
+
233
237
  backgroundcolor: all matplotlib color formats (without X11/xkcd), optional
234
238
  Background color of text box: RGB/RGBA (tuple), HEX (str), grayscale (float), single-char (str), name (str), default cycle ("CX", X int), none for invisible
235
239
 
@@ -248,9 +252,9 @@ class BaseAxes:
248
252
  ...
249
253
  def hlines(
250
254
  self,
251
- y: Union[float, Sequence[float]],
252
- xmin: Union[float, Sequence[float]],
253
- xmax: Union[float, Sequence[float]],
255
+ y: Union[float, ArrayLike],
256
+ xmin: Union[float, ArrayLike],
257
+ xmax: Union[float, ArrayLike],
254
258
  colors: Union[str, Sequence[str]] = "k",
255
259
  linestyles: Union[str, Sequence[str]] = "solid",
256
260
  ) -> None:
@@ -260,9 +264,9 @@ class BaseAxes:
260
264
  ...
261
265
  def vlines(
262
266
  self,
263
- x: Union[float, Sequence[float]],
264
- ymin: Union[float, Sequence[float]],
265
- ymax: Union[float, Sequence[float]],
267
+ x: Union[float, ArrayLike],
268
+ ymin: Union[float, ArrayLike],
269
+ ymax: Union[float, ArrayLike],
266
270
  colors: Union[str, Sequence[str]] = "k",
267
271
  linestyles: Union[str, Sequence[str]] = "solid",
268
272
  ) -> None:
@@ -468,7 +472,7 @@ class BaseAxes:
468
472
  Set y-axis scale (to log).
469
473
  """
470
474
  ...
471
- def set_yticks(self, ticks: Sequence[float], labels: Optional[Sequence[str]] = ...) -> None:
475
+ def set_yticks(self, ticks: ArrayLike, labels: Optional[Sequence[str]] = ...) -> None:
472
476
  """
473
477
  Set y-axis ticks and their labels.
474
478
  """
@@ -499,9 +503,17 @@ class BaseAxes:
499
503
  Set parameter (lims, labels, ticks, ticklabels, title)
500
504
  """
501
505
  ...
506
+ def _add_legend_entries(self) -> str: ...
507
+ def _content_tex(self, filename: str) -> str: ...
508
+ def _get_hard_range(self, which: Literal["xmin","xmax","ymin","ymax"]) -> Tuple[float,str]: ...
509
+ def _get_range(self, which: Literal["xmin","xmax","ymin","ymax"]) -> Tuple[float, bool,str]: ...
510
+ def _get_limit(self, which: Literal["xmin","xmax","ymin","ymax"]) -> Tuple[float,bool,str]: ...
511
+ def _set_range(self, which: Literal["xmin","xmax","ymin","ymax"], value: Union[float, int]): ...
512
+ def _num_points(self) -> list[int]: ...
513
+ # def _add_color(self, ?) -> None: ...
502
514
 
503
515
  class Axes(BaseAxes):
504
- def __init__(self, nrows: int, ncols: int, index: int, fig: Any) -> None: ...
516
+ def __init__(self, nrows: int, ncols: int, index: int, fig: Any, pol: bool) -> None: ...
505
517
  def loglog(self, x: ArrayLike = ..., y: ArrayLike = ..., base: Optional[float] = 10, fmt: Optional[str] = ...,*, alpha: Optional[float] = ..., color: Optional[ColorLike] = ..., c: Optional[ColorLike] = ...,
506
518
  linestyle: Optional[LineStyle] = ..., ls: Optional[LineStyle] = ..., linewidth: Optional[float]= ..., lw: Optional[float] = ...,
507
519
  marker: Optional[MarkerStyle] = ..., markersize: Optional[float] = ..., ms: Optional[float] = ...) -> None:
@@ -580,7 +592,7 @@ class Axes(BaseAxes):
580
592
  Mark size in pt
581
593
  """
582
594
  ...
583
- def imshow(self, *args: Any, cmap: Optional[str] = ...) -> Tuple[Any, str, float, float]:
595
+ def imshow(self, *args: Any, cmap: Optional[str] = ..., **kwargs: Any) -> Tuple[Any, str, float, float]:
584
596
  """
585
597
  Draw image to the selected axis from array. Uses matplotlib imshow() to export to PDF, then inputs the image to the axis. Return may be used to initialize Colorbar().
586
598
  """
@@ -636,14 +648,14 @@ class Axes(BaseAxes):
636
648
  Set x-axis scale (to log).
637
649
  """
638
650
  ...
639
- def set_xticks(self, ticks: Sequence[float], labels: Optional[Sequence[str]] = ...) -> None:
651
+ def set_xticks(self, ticks: ArrayLike, labels: Optional[Sequence[str]] = ...) -> None:
640
652
  """
641
653
  Set x-axis ticks and their labels.
642
654
  """
643
655
  ...
644
656
  def set_xticklabels(self, labels: Sequence[str]) -> None:
645
657
  """
646
- Set y-axis tick labels.
658
+ Set x-axis tick labels.
647
659
  """
648
660
  ...
649
661
  def twinx(self) -> "Secondary":
@@ -651,6 +663,22 @@ class Axes(BaseAxes):
651
663
  Initialize secondary y-axis.
652
664
  """
653
665
  ...
666
+ def _export_imshow(self, *args: Any, **kwargs: Any) -> str: ...
667
+ def _axis_options_string(self) -> str: ...
668
+ def _margins(self) -> tuple[float, float, float, float]: ...
669
+ def _get_row(self) -> int: ...
670
+ def _get_col(self) -> int: ...
671
+ def _get_nrows(self) -> int: ...
672
+ def _get_ncols(self) -> int: ...
673
+ def _get_defcol(self) -> int: ...
674
+ def _show_colorbar(self, cbar: str, horizontal: bool = ...) -> None: ...
675
+ def _get_index(self) -> int: ...
676
+ def _to_tex(self, filename: str, single: bool) -> tuple[list[str], list[str]]: ...
677
+
654
678
 
655
679
  class Secondary(BaseAxes):
656
- def __init__(self, primary: Axes) -> None: ...
680
+ def __init__(self, primary: Axes) -> None: ...
681
+ def _axis_options_string(self) -> str: ...
682
+ def _padding(self) -> float: ...
683
+ def _get_defcol(self) -> int: ...
684
+ def _get_index(self) -> int: ...
@@ -19,7 +19,7 @@ class Axes3:
19
19
  if TikzConfig.USE_DECIMAL_COMMA:
20
20
  self._axis_args.add("/pgf/number format/use comma")
21
21
 
22
- self._add_legend = ""
22
+ self._add_legend = []
23
23
 
24
24
  self._left = False
25
25
  self._neigh = None
@@ -31,7 +31,8 @@ class Axes3:
31
31
  self._col = self._index - self._row * self._ncols
32
32
 
33
33
  self._fig = fig
34
-
34
+ self._style = self._fig._style
35
+
35
36
  self._defcol_counter = 0
36
37
  self._colorbar = ""
37
38
  self._cbar_h = False
@@ -60,7 +61,20 @@ class Axes3:
60
61
  if self._fig._get_height():
61
62
  self._height = f"{self._fig._get_height() / nrows}cm"
62
63
 
63
- def _plot(self, xs, ys, zs, zdir="z", settings=None, xerr=None, yerr=None, zerr=None, **style):
64
+ self._style_defaults()
65
+
66
+ def _style_defaults(self):
67
+ _gs = self._style._get_grid_cycle()
68
+ if _gs is not None:
69
+ self.grid(**_gs)
70
+ _bcgnd = self._style._get_background_cycle()
71
+ if _bcgnd is not None:
72
+ self._axis_options["axis background/.style"] = f"{{{_bcgnd}}}"
73
+ _add_settgs = self._style._get_additional_settings()
74
+ if _add_settgs is not None:
75
+ self._axis_options = _add_settgs | self._axis_options
76
+
77
+ def _plot(self, xs, ys, zs, zdir="z", settings=[], xerr=None, yerr=None, zerr=None, **style):
64
78
  if isinstance(zs, (float,int)):
65
79
  zs = [zs] * len(xs)
66
80
  if zdir == "y":
@@ -126,6 +140,7 @@ class Axes3:
126
140
  if el._check_equal(xs,ys,zs):
127
141
  return el._try_set_pname(pname)
128
142
  return None
143
+ assert self._fig is not None
129
144
  name1 = self._fig._get_free_path_name()
130
145
  name2 = self._fig._get_free_path_name()
131
146
  if isinstance(y1, (int, float)):
@@ -156,7 +171,7 @@ class Axes3:
156
171
  self._plot(xs,ys,path_name=name2, alpha=0)
157
172
  else:
158
173
  name2 = inst"""
159
- e = Graph3(self, f"fill between [of={name1} and {name2}]",settings=None, xerr=None, yerr=None, zerr=None, **kwargs)
174
+ e = Graph3(self, f"fill between [of={name1} and {name2}]",settings=[], xerr=None, yerr=None, zerr=None, **kwargs)
160
175
  self._elements.append(e)
161
176
  return e
162
177
 
@@ -395,7 +410,7 @@ class Axes3:
395
410
  legend_string = []
396
411
  if lx is not None and ly is not None:
397
412
  legend_string.append(r"at={(" + f"{lx},{ly}" + r")}")
398
- if len(posit):
413
+ if posit is not None and len(posit):
399
414
  legend_string.append(r"anchor=" + posit)
400
415
  else: print(posit)
401
416
  self._axis_options["legend style"] = f"{{{','.join(legend_string)}}}"
@@ -423,7 +438,7 @@ class Axes3:
423
438
  self._axis_options["rotate around z"] = f"{{{roll}}}"
424
439
 
425
440
  def _add_legend_entries(self):
426
- if self._add_legend == "": return ""
441
+ if self._add_legend == []: return ""
427
442
  axs, labs = self._add_legend
428
443
  output = ""
429
444
  if len(axs) != len(labs):
@@ -481,9 +496,11 @@ class Axes3:
481
496
  e._reduce_points(limit, logx, logy)
482
497
 
483
498
  def _add_col(self, r,g,b):
499
+ assert self._fig is not None
484
500
  self._fig._add_col(r,g,b)
485
501
 
486
502
  def _update_size(self):
503
+ assert self._fig is not None
487
504
  if self._fig._get_width():
488
505
  self._width= f"{self._fig._get_width() / self._ncols}cm"
489
506
  if self._fig._get_height():
@@ -512,6 +529,7 @@ class Axes3:
512
529
  if self._height:
513
530
  self._axis_options["height"] = self._height
514
531
  if not TikzConfig.USE_GROUPPLOTS:
532
+ assert self._fig is not None
515
533
  if self._left:
516
534
  self._axis_options["yshift"] = f"-{self._fig._get_spacing(self._row, self._col)}cm"
517
535
  else:
@@ -0,0 +1,43 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional, Union, Sequence
4
+
5
+ import numpy as np
6
+
7
+ from .colorbar import Colorbar
8
+
9
+ ArrayLike = np.ndarray | list[float] | tuple[float, ...]
10
+ ColorLike = Union[str, Sequence[float], Sequence[Sequence[float] | ArrayLike], np.ndarray, None]
11
+ LineStyle = str
12
+ MarkerStyle = str
13
+
14
+
15
+ class Axes3:
16
+ def __init__(self, nrows: int, ncols: int, index: int, fig: Any) -> None: ...
17
+ def plot(self, xs: Union[ArrayLike, float, int], ys: Union[ArrayLike, float, int], zs: Union[ArrayLike, float, int], zdir: str = ..., **kwargs: Any) -> Any: ...
18
+ def scatter(self, xs: Union[ArrayLike, float, int], ys: Union[ArrayLike, float, int], zs: Union[ArrayLike, float, int] = ..., zdir: str = ..., *args: Any, **kwargs: Any) -> Any: ...
19
+ def plot_surface(self, X: np.ndarray, Y: np.ndarray, Z: np.ndarray, **kwargs: Any) -> Any: ...
20
+ def plot_wireframe(self, X: np.ndarray, Y: np.ndarray, Z: np.ndarray, **kwargs: Any) -> Any: ...
21
+ def errorbar(self, x: Union[ArrayLike, float, int], y: Union[ArrayLike, float, int], z: Union[ArrayLike, float, int], zerr: Optional[Union[ArrayLike, float, int] | float] = ..., yerr: Optional[Union[ArrayLike, float, int] | float] = ..., xerr: Optional[Union[ArrayLike, float, int] | float] = ..., **kwargs: Any) -> Any: ...
22
+ def fill_between(self, x1: Union[ArrayLike, float, int], y1: Union[ArrayLike, float, int], z1: Union[ArrayLike, float, int], x2: Union[ArrayLike, float, int], y2: Union[ArrayLike, float, int], z2: Union[ArrayLike, float, int], *, alpha: Optional[float] = ..., color: Optional[ColorLike] = ..., c: Optional[ColorLike] = ..., label: Optional[str] = ...) -> Any: ...
23
+ def text(self, x: float, y: float, z: float, s: str, **kwargs: Any) -> None: ...
24
+ def set_title(self, title: str) -> None: ...
25
+ def set_xlabel(self, label: str) -> None: ...
26
+ def set_ylabel(self, label: str) -> None: ...
27
+ def set_zlabel(self, label: str) -> None: ...
28
+ def set_xlim(self, *args: Any, **kwargs: Any) -> None: ...
29
+ def set_ylim(self, *args: Any, **kwargs: Any) -> None: ...
30
+ def set_zlim(self, *args: Any, **kwargs: Any) -> None: ...
31
+ def set_xscale(self, *args: Any, **kwargs: Any) -> None: ...
32
+ def set_yscale(self, *args: Any, **kwargs: Any) -> None: ...
33
+ def set_zscale(self, *args: Any, **kwargs: Any) -> None: ...
34
+ def set_xticks(self, ticks: Any, labels: Any = ...) -> None: ...
35
+ def set_yticks(self, ticks: Any, labels: Any = ...) -> None: ...
36
+ def set_zticks(self, ticks: Any, labels: Any = ...) -> None: ...
37
+ def set_xticklabels(self, labels: Any) -> None: ...
38
+ def set_yticklabels(self, labels: Any) -> None: ...
39
+ def set_zticklabels(self, labels: Any) -> None: ...
40
+ def legend(self, *args: Any, **kwargs: Any) -> None: ...
41
+ def view_init(self, elev: Optional[float] = ..., azim: Optional[float] = ..., roll: Optional[float] = ...) -> None: ...
42
+ def grid(self, visible: bool = ..., which: str = ...) -> None: ...
43
+ def set(self, **kwargs: Any) -> None: ...
@@ -1,4 +1,6 @@
1
1
  import numpy as _np
2
+
3
+ from tikzplot.styles import Styles
2
4
  from .elements import Graph
3
5
  from .axes3d import Axes3
4
6
  from .config import TikzConfig
@@ -44,6 +46,9 @@ class _Colorbar:
44
46
  self._divs = kwargs["divisions"]
45
47
  if self._axis:
46
48
  self._axis._show_colorbar(str(self))
49
+
50
+ if self._cmap is None:
51
+ self._cmap = "viridis"
47
52
 
48
53
  _discrete = {'Pastel1':9, 'Pastel2':8, 'Paired':12, 'Accent':8, 'Dark2':8, 'Set1': 9, 'Set2':8, 'Set3':12, 'tab10':10, 'tab20':20, 'tab20b':20, 'tab20c':20}
49
54
  _dictionary = {
@@ -186,11 +191,15 @@ class _Colorbar:
186
191
  return "\n".join(output)
187
192
 
188
193
  def __str__(self):
194
+ assert self._axis is not None
189
195
  tridim = isinstance(self._axis, Axes3)
190
196
  lines = []
191
197
  lines.append(f"colormap={self._generate_tex_colormap(self._cmap)},")
192
198
  lines.append(f"colorbar{' horizontal' if self._horizontal else ''},")
193
199
  lines.append(r"colorbar style={")
200
+ if hasattr(self._axis._fig, "_style"):
201
+ _st_settings = self._axis._fig._style._get_colorbar_settings()
202
+ else: _st_settings = {}
194
203
  if TikzConfig.USE_DECIMAL_COMMA:
195
204
  lines.append("/pgf/number format/use comma,")
196
205
  if self._horizontal:
@@ -208,10 +217,13 @@ class _Colorbar:
208
217
  if self._label:
209
218
  lines.append(f"title={{{self._label}}},")
210
219
  offset = 4 - 2 * (self._ticks == [] or self._tick_labels == [])
220
+ _add_color = ""
221
+ if _st_settings and "text" in _st_settings:
222
+ _add_color = f", text={_st_settings['text']}"
211
223
  if self._horizontal:
212
- lines.append(f"title style={{at={{(0.5, -{offset})}}, anchor=base}},")
224
+ lines.append(f"title style={{at={{(0.5, -{offset})}}, anchor=base{_add_color}}}, ")
213
225
  else:
214
- lines.append(f"title style={{at={{({offset},0.5)}}, anchor=base, yshift=-7pt, rotate=-90}},")
226
+ lines.append(f"title style={{at={{({offset},0.5)}}, anchor=base, yshift=-7pt, rotate=-90{_add_color}}},")
215
227
  if self._ticks is not None:
216
228
  lines.append(f"{'x' if self._horizontal else 'y'}tick={{{','.join(str(a) for a in self._ticks)}}},")
217
229
  if self._tick_labels and len(self._tick_labels) == len(self._ticks):
@@ -20,22 +20,22 @@ class Colorbar:
20
20
  where `im` is a tuple describing an image:
21
21
  (axis, cmap, lower, upper)
22
22
  """
23
-
23
+ _cmap: Any
24
24
  def __init__(
25
25
  self,
26
- im: Optional[Tuple[Axes, str, float, float]] = ...,
26
+ im: Optional[Tuple[Axes, str, float, float]] = None,
27
27
  *,
28
- axis: Optional[Axes | Axes3] = ...,
29
- cmap: Optional[str] = ...,
30
- lower: Optional[float] = ...,
31
- upper: Optional[float] = ...,
32
- ticks: Optional[Sequence[ float]] = ...,
33
- tick_labels: Optional[Sequence[str | float]] = ...,
34
- label: Optional[str] = ...,
35
- width: Optional[float] = ...,
36
- horizontal: Optional[bool] = ...,
37
- rel_len: Optional[float] = ...,
38
- divisions: Optional[int] = ...
28
+ axis: Optional[Axes | Axes3] = None,
29
+ cmap: Optional[str] = "viridis",
30
+ lower: Optional[float] = 0,
31
+ upper: Optional[float] = 1,
32
+ ticks: Optional[Sequence[ float]] = None,
33
+ tick_labels: Optional[Sequence[str | float]] = None,
34
+ label: Optional[str] = None,
35
+ width: Optional[float] = 0.3,
36
+ horizontal: Optional[bool] = None,
37
+ rel_len: Optional[float] = 1,
38
+ divisions: Optional[int] = 0
39
39
  ) -> None:
40
40
  """
41
41
  Parameters