File tree Expand file tree Collapse file tree 3 files changed +12
-11
lines changed Expand file tree Collapse file tree 3 files changed +12
-11
lines changed Original file line number Diff line number Diff line change 1
- import matplotlib as mpl
1
+ import matplotlib . pyplot as plt
2
2
import numpy as np
3
3
import PIL
4
4
@@ -9,16 +9,16 @@ def draw_image(data, obj):
9
9
"""Returns the PGFPlots code for an image environment."""
10
10
content = []
11
11
12
- filename , rel_filepath = _files .new_filename (data , "img" , ".png" )
12
+ filepath , rel_filepath = _files .new_filepath (data , "img" , ".png" )
13
13
14
14
# store the image as in a file
15
15
img_array = obj .get_array ()
16
16
17
17
dims = img_array .shape
18
18
if len (dims ) == 2 : # the values are given as one real number: look at cmap
19
19
clims = obj .get_clim ()
20
- mpl . pyplot .imsave (
21
- fname = filename ,
20
+ plt .imsave (
21
+ fname = filepath ,
22
22
arr = img_array ,
23
23
cmap = obj .get_cmap (),
24
24
vmin = clims [0 ],
@@ -40,7 +40,7 @@ def draw_image(data, obj):
40
40
# If the input image is PIL:
41
41
# image = PIL.Image.fromarray(img_array)
42
42
43
- image .save (filename , origin = obj .origin )
43
+ image .save (filepath , origin = obj .origin )
44
44
45
45
# write the corresponding information to the TikZ file
46
46
extent = obj .get_extent ()
Original file line number Diff line number Diff line change @@ -45,9 +45,10 @@ def draw_line2d(data, obj):
45
45
style = "const plot mark mid"
46
46
elif drawstyle in ["steps-pre" , "steps" ]:
47
47
style = "const plot mark right"
48
- elif drawstyle == "steps-post" :
48
+ else :
49
+ assert drawstyle == "steps-post"
49
50
style = "const plot mark left"
50
- addplot_options .append (f" { style } " )
51
+ addplot_options .append (style )
51
52
52
53
alpha = obj .get_alpha ()
53
54
if alpha is not None :
@@ -279,8 +280,8 @@ def _table(obj, data): # noqa: C901
279
280
plot_table .append (f"{ x :{xformat }} { col_sep } { y :{ff }} { table_row_sep } " )
280
281
281
282
if data ["externalize tables" ]:
282
- filename , rel_filepath = _files .new_filename (data , "table" , ".tsv" )
283
- with open (filename , "w" ) as f :
283
+ filepath , rel_filepath = _files .new_filepath (data , "table" , ".tsv" )
284
+ with open (filepath , "w" ) as f :
284
285
# No encoding handling required: plot_table is only ASCII
285
286
f .write ("" .join (plot_table ))
286
287
content .append (rel_filepath )
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ def draw_quadmesh(data, obj):
10
10
content = []
11
11
12
12
# Generate file name for current object
13
- filename , rel_filepath = _files .new_filename (data , "img" , ".png" )
13
+ filepath , rel_filepath = _files .new_filepath (data , "img" , ".png" )
14
14
15
15
# Get the dpi for rendering and store the original dpi of the figure
16
16
dpi = data ["dpi" ]
@@ -42,7 +42,7 @@ def draw_quadmesh(data, obj):
42
42
int (round (cbox .extents [3 ] - cbox .extents [1 ])),
43
43
)
44
44
cropped = image .crop (box )
45
- cropped .save (filename )
45
+ cropped .save (filepath )
46
46
47
47
# Restore the original dpi of the figure
48
48
obj .figure .set_dpi (fig_dpi )
You can’t perform that action at this time.
0 commit comments