tikzplotly 0.1.2__tar.gz → 0.1.4__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 (31) hide show
  1. {tikzplotly-0.1.2/src/tikzplotly.egg-info → tikzplotly-0.1.4}/PKG-INFO +3 -1
  2. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/README.md +1 -0
  3. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/pyproject.toml +3 -2
  4. tikzplotly-0.1.4/src/tests/test_heatmaps.py +206 -0
  5. tikzplotly-0.1.4/src/tests/test_markers.py +392 -0
  6. tikzplotly-0.1.4/src/tikzplotly/__about__.py +1 -0
  7. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly/_axis.py +19 -20
  8. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly/_color.py +34 -5
  9. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly/_dataContainer.py +6 -4
  10. tikzplotly-0.1.4/src/tikzplotly/_heatmap.py +145 -0
  11. tikzplotly-0.1.4/src/tikzplotly/_marker.py +121 -0
  12. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly/_save.py +19 -4
  13. tikzplotly-0.1.4/src/tikzplotly/_scatter.py +132 -0
  14. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly/_tex.py +12 -2
  15. tikzplotly-0.1.4/src/tikzplotly/_utils.py +132 -0
  16. {tikzplotly-0.1.2 → tikzplotly-0.1.4/src/tikzplotly.egg-info}/PKG-INFO +3 -1
  17. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly.egg-info/SOURCES.txt +5 -2
  18. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly.egg-info/requires.txt +1 -0
  19. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly.egg-info/top_level.txt +1 -0
  20. tikzplotly-0.1.2/src/tikzplotly/__about__.py +0 -1
  21. tikzplotly-0.1.2/src/tikzplotly/_marker.py +0 -22
  22. tikzplotly-0.1.2/src/tikzplotly/_scatter.py +0 -87
  23. tikzplotly-0.1.2/src/tikzplotly/_utils.py +0 -38
  24. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/LICENSE +0 -0
  25. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/setup.cfg +0 -0
  26. {tikzplotly-0.1.2 → tikzplotly-0.1.4/src}/tests/test_line_charts.py +0 -0
  27. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly/__init__.py +0 -0
  28. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly/_annotations.py +0 -0
  29. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly/_dash.py +0 -0
  30. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly/_data.py +0 -0
  31. {tikzplotly-0.1.2 → tikzplotly-0.1.4}/src/tikzplotly.egg-info/dependency_links.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tikzplotly
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: Convert plotly figures to LaTeX / tikz figures
5
5
  Author-email: Thomas Saigre <tikzplotly@outlook.fr>
6
6
  License: The MIT License (MIT)
@@ -42,6 +42,7 @@ Description-Content-Type: text/markdown
42
42
  License-File: LICENSE
43
43
  Requires-Dist: numpy
44
44
  Requires-Dist: plotly
45
+ Requires-Dist: PIL
45
46
  Provides-Extra: dev
46
47
  Requires-Dist: pandas; extra == "dev"
47
48
 
@@ -140,6 +141,7 @@ To correctly compile the document, you will need to add the following packages t
140
141
  * This module is in development and new features are added bit by bit, when needed. If you have a feature request, please open an issue with the plotly figure you want to convert and the desired output.
141
142
  You can also submit a pull request with the desired feature !
142
143
  * Some feature can result in different output between the plotly figure and the tikz figure, for instance the size of markers.
144
+ * More details in [doc/NB.md](doc/NB.md).
143
145
 
144
146
 
145
147
  ## References
@@ -93,6 +93,7 @@ To correctly compile the document, you will need to add the following packages t
93
93
  * This module is in development and new features are added bit by bit, when needed. If you have a feature request, please open an issue with the plotly figure you want to convert and the desired output.
94
94
  You can also submit a pull request with the desired feature !
95
95
  * Some feature can result in different output between the plotly figure and the tikz figure, for instance the size of markers.
96
+ * More details in [doc/NB.md](doc/NB.md).
96
97
 
97
98
 
98
99
  ## References
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tikzplotly"
7
- version = "0.1.2"
7
+ version = "0.1.4"
8
8
  description = "Convert plotly figures to LaTeX / tikz figures"
9
9
  readme = "README.md"
10
10
  authors = [{name = "Thomas Saigre", email = "tikzplotly@outlook.fr"}]
@@ -25,7 +25,8 @@ classifiers = [
25
25
  keywords = ["plotly", "latex", "tikz", "figure", "conversion", "graphics"]
26
26
  dependencies = [
27
27
  "numpy",
28
- "plotly"
28
+ "plotly",
29
+ "PIL"
29
30
  ]
30
31
 
31
32
  [project.optional-dependencies]
@@ -0,0 +1,206 @@
1
+ # From https://plotly.com/python/heatmaps/
2
+ import os
3
+ import tikzplotly
4
+
5
+ from tikzplotly._tex import tex_create_document, tex_begin_environment, tex_end_environment, tex_end_all_environment
6
+
7
+ import plotly
8
+ import plotly.express as px
9
+ import pandas as pd
10
+ import plotly.graph_objects as go
11
+ import numpy as np
12
+ import datetime
13
+ import numpy as np
14
+ np.random.seed(1)
15
+
16
+ def fig1():
17
+ fig = px.imshow([[1, 20, 30],
18
+ [20, 1, 60],
19
+ [30, 60, 1]])
20
+ # fig.show()
21
+ return fig, "Heatmaps with Plotly Express"
22
+
23
+ def fig2():
24
+ df = px.data.medals_wide(indexed=True)
25
+ fig = px.imshow(df)
26
+ # fig.show()
27
+ return fig, "Heatmaps with Plotly Express 2"
28
+
29
+ def fig3():
30
+ z = [[.1, .3, .5, .7, .9],
31
+ [1, .8, .6, .4, .2],
32
+ [.2, 0, .5, .7, .9],
33
+ [.9, .8, .4, .2, 0],
34
+ [.3, .4, .5, .7, 1]]
35
+
36
+ fig = px.imshow(z, text_auto=True)
37
+ # fig.show()
38
+ return fig, "Displaying Text on Heatmaps"
39
+
40
+ def fig4():
41
+ z = [[.1, .3, .5, .7, .9],
42
+ [1, .8, .6, .4, .2],
43
+ [.2, 0, .5, .7, .9],
44
+ [.9, .8, .4, .2, 0],
45
+ [.3, .4, .5, .7, 1]]
46
+
47
+ fig = px.imshow(z, text_auto=True, aspect="auto")
48
+ # fig.show()
49
+ return fig, "Controlling Aspect Ratio"
50
+
51
+ def fig5():
52
+ data=[[1, 25, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, 5, 20]]
53
+ fig = px.imshow(data,
54
+ labels=dict(x="Day of Week", y="Time of Day", color="Productivity"),
55
+ x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
56
+ y=['Morning', 'Afternoon', 'Evening']
57
+ )
58
+ fig.update_xaxes(side="top")
59
+ # fig.show()
60
+ return fig, "Customizing the axes and labels on a heatmap"
61
+
62
+ def fig6():
63
+
64
+ fig = go.Figure(data=go.Heatmap(
65
+ z=[[1, 20, 30],
66
+ [20, 1, 60],
67
+ [30, 60, 1]]))
68
+ # fig.show()
69
+ return fig, "Basic Heatmap with plotly.graph\\_objects"
70
+
71
+ def fig7():
72
+ fig = go.Figure(data=go.Heatmap(
73
+ z=[[1, None, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]],
74
+ x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
75
+ y=['Morning', 'Afternoon', 'Evening'],
76
+ hoverongaps = False))
77
+ # fig.show()
78
+ return fig, "Heatmap with Categorical Axis Labels"
79
+
80
+ def fig8():
81
+ import plotly.graph_objects as go
82
+
83
+ # Build the rectangles as a heatmap
84
+ # specify the edges of the heatmap squares
85
+ phi = (1 + np.sqrt(5) )/2. # golden ratio
86
+ xe = [0, 1, 1+(1/(phi**4)), 1+(1/(phi**3)), phi]
87
+ ye = [0, 1/(phi**3), 1/phi**3+1/phi**4, 1/(phi**2), 1]
88
+
89
+ z = [ [13,3,3,5],
90
+ [13,2,1,5],
91
+ [13,10,11,12],
92
+ [13,8,8,8]
93
+ ]
94
+
95
+ fig = go.Figure(data=go.Heatmap(
96
+ x = np.sort(xe),
97
+ y = np.sort(ye),
98
+ z = z,
99
+ type = 'heatmap',
100
+ colorscale = 'Viridis'))
101
+
102
+ # Add spiral line plot
103
+
104
+ def spiral(th):
105
+ a = 1.120529
106
+ b = 0.306349
107
+ r = a*np.exp(-b*th)
108
+ return (r*np.cos(th), r*np.sin(th))
109
+
110
+ theta = np.linspace(-np.pi/13,4*np.pi,1000); # angle
111
+ (x,y) = spiral(theta)
112
+
113
+ fig.add_trace(go.Scatter(x= -x+x[0], y= y-y[0],
114
+ line =dict(color='white',width=3)))
115
+
116
+ axis_template = dict(range = [0,1.6], autorange = False,
117
+ showgrid = False, zeroline = False,
118
+ linecolor = 'black', showticklabels = False,
119
+ ticks = '' )
120
+
121
+ fig.update_layout(margin = dict(t=200,r=200,b=200,l=200),
122
+ xaxis = axis_template,
123
+ yaxis = axis_template,
124
+ showlegend = False,
125
+ width = 700, height = 700,
126
+ autosize = False )
127
+
128
+ # fig.show()
129
+ return fig, "Heatmap with Unequal Block Sizes"
130
+
131
+
132
+ def fig9():
133
+ import plotly.graph_objects as go
134
+
135
+
136
+ programmers = ['Alex','Nicole','Sara','Etienne','Chelsea','Jody','Marianne']
137
+
138
+ base = datetime.datetime.today()
139
+ dates = base - np.arange(180) * datetime.timedelta(days=1)
140
+ z = np.random.poisson(size=(len(programmers), len(dates)))
141
+
142
+ fig = go.Figure(data=go.Heatmap(
143
+ z=z,
144
+ x=dates,
145
+ y=programmers,
146
+ colorscale='Viridis'))
147
+
148
+ fig.update_layout(
149
+ title='GitHub commits per day',
150
+ xaxis_nticks=36)
151
+
152
+ # fig.show()
153
+ return fig, "Heatmap with Datetime Axis"
154
+
155
+
156
+ def fig11(): # from @JasonGross, see issue https://github.com/thomas-saigre/tikzplotly/issues/6
157
+ data = np.random.rand(10,10)
158
+ fig = px.imshow(data, color_continuous_scale='Viridis', title='Heatmap Example with Plotly Express')
159
+ # fig.show()
160
+ return fig, "Heatmap Example with Plotly Express"
161
+
162
+ if __name__ == "__main__":
163
+
164
+ print("Tikzploty : ", tikzplotly.__version__)
165
+ print("Plotly : ", plotly.__version__)
166
+ print("Test line charts")
167
+
168
+ file_directory = os.path.dirname(os.path.abspath(__file__))
169
+
170
+ functions = [
171
+ ("1", fig1),
172
+ ("2", fig2),
173
+ # ("3", fig3), # texttemplate not supported
174
+ ("4", fig4),
175
+ ("5", fig5),
176
+ ("6", fig6),
177
+ ("7", fig7),
178
+ # ("8", fig8), # Not supported
179
+ ("9", fig9),
180
+ ("11", fig11)
181
+
182
+ ]
183
+
184
+ main_tex_content = tex_create_document(options="twocolumn", compatibility="newest")
185
+ main_tex_content += "\\usepackage[left=1cm, right=1cm, top=1cm, bottom=1cm]{geometry}\n"
186
+ main_tex_content += "\n"
187
+ stack_env = []
188
+ main_tex_content += tex_begin_environment("document", stack_env) + '\n'
189
+
190
+ for i, f in functions:
191
+ print(f"Figure {i}")
192
+ fig, title = f()
193
+ data = fig.data
194
+ save_path = os.path.join(file_directory, "outputs", "test_heatmap", "fig{}.tex".format(i))
195
+ tikzplotly.save(save_path, fig, img_name=os.path.join(file_directory, "outputs", "test_heatmap", "fig{}.png".format(i)))
196
+ main_tex_content += tex_begin_environment("figure", stack_env)
197
+ main_tex_content += " \\input{fig" + str(i) + ".tex}\n"
198
+ main_tex_content += " \\caption{" + title + "}\n"
199
+ main_tex_content += tex_end_environment(stack_env) + '\n'
200
+
201
+ main_tex_content += "\n" + tex_end_all_environment(stack_env)
202
+
203
+ main_tex_path = os.path.join(file_directory, "outputs", "test_heatmap", "main.tex")
204
+ print("Save main tex file : ", main_tex_path)
205
+ with open(main_tex_path, "w") as f:
206
+ f.write(main_tex_content)
@@ -0,0 +1,392 @@
1
+ # From https://plotly.com/python/marker-style/
2
+ import plotly
3
+ import plotly.express as px
4
+ import pandas as pd
5
+ import plotly.graph_objects as go
6
+ import numpy as np
7
+ import tikzplotly
8
+ import os
9
+ import plotly.graph_objects as go
10
+ from plotly.validators.scatter.marker import SymbolValidator
11
+ from warnings import warn
12
+ from tikzplotly._tex import tex_create_document, tex_begin_environment, tex_end_environment, tex_end_all_environment
13
+
14
+ def fig1():
15
+
16
+ df = px.data.iris()
17
+ fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
18
+
19
+ fig.update_traces(marker=dict(size=12,
20
+ line=dict(width=2,
21
+ color='DarkSlateGrey')),
22
+ selector=dict(mode='markers'))
23
+ # fig.show()
24
+
25
+ return fig, "add marker border"
26
+
27
+ def fig2():
28
+ np.random.seed(1)
29
+
30
+ x = np.random.uniform(low=3, high=6, size=(500,))
31
+ y = np.random.uniform(low=3, high=6, size=(500,))
32
+
33
+ # Build figure
34
+ fig = go.Figure()
35
+
36
+ # Add scatter trace with medium sized markers
37
+ fig.add_trace(
38
+ go.Scatter(
39
+ mode='markers',
40
+ x=x,
41
+ y=y,
42
+ marker=dict(
43
+ color='LightSkyBlue',
44
+ size=20,
45
+ line=dict(
46
+ color='MediumPurple',
47
+ width=2
48
+ )
49
+ ),
50
+ showlegend=False
51
+ )
52
+ )
53
+
54
+ # Add trace with large marker
55
+ fig.add_trace(
56
+ go.Scatter(
57
+ mode='markers',
58
+ x=[2],
59
+ y=[4.5],
60
+ marker=dict(
61
+ color='LightSkyBlue',
62
+ size=120,
63
+ line=dict(
64
+ color='MediumPurple',
65
+ width=12
66
+ )
67
+ ),
68
+ showlegend=False
69
+ )
70
+ )
71
+
72
+ return fig, "Add marker border 2"
73
+
74
+
75
+ def fig3():
76
+ x = np.random.uniform(low=3, high=6, size=(500,))
77
+ y = np.random.uniform(low=3, high=4.5, size=(500,))
78
+ x2 = np.random.uniform(low=3, high=6, size=(500,))
79
+ y2 = np.random.uniform(low=4.5, high=6, size=(500,))
80
+
81
+ # Build figure
82
+ fig = go.Figure()
83
+
84
+ # Add first scatter trace with medium sized markers
85
+ fig.add_trace(
86
+ go.Scatter(
87
+ mode='markers',
88
+ x=x,
89
+ y=y,
90
+ opacity=0.5,
91
+ marker=dict(
92
+ color='LightSkyBlue',
93
+ size=3,
94
+ line=dict(color='MediumPurple')
95
+ ),
96
+ name='Opacity 0.5'
97
+ )
98
+ )
99
+
100
+ # Add second scatter trace with medium sized markers
101
+ # and opacity 1.0
102
+ fig.add_trace(
103
+ go.Scatter(
104
+ mode='markers',
105
+ x=x2,
106
+ y=y2,
107
+ marker=dict(
108
+ color='LightSkyBlue',
109
+ size=3,
110
+ line=dict(color='MediumPurple')
111
+ ),
112
+ name='Opacity 1.0'
113
+ )
114
+ )
115
+
116
+ # Add trace with large markers
117
+ fig.add_trace(
118
+ go.Scatter(
119
+ mode='markers',
120
+ x=[2, 2],
121
+ y=[4.25, 4.75],
122
+ marker=dict(
123
+ opacity=0.5,
124
+ color='LightSkyBlue',
125
+ size=10,
126
+ line=dict(color='MediumPurple')
127
+ ),
128
+ showlegend=False
129
+ )
130
+ )
131
+
132
+ return fig, "Opacity"
133
+
134
+ def fig3bis():
135
+ x = np.random.uniform(low=3, high=6, size=(500,))
136
+ y = np.random.uniform(low=3, high=6, size=(500,))
137
+
138
+ # Build figure
139
+ fig = go.Figure()
140
+
141
+ # Add scatter trace with medium sized markers
142
+ fig.add_trace(
143
+ go.Scatter(
144
+ mode='markers',
145
+ x=x,
146
+ y=y,
147
+ marker=dict(
148
+ color='LightSkyBlue',
149
+ size=20,
150
+ opacity=0.5,
151
+ line=dict(
152
+ color='MediumPurple',
153
+ width=2
154
+ )
155
+ ),
156
+ showlegend=False
157
+ )
158
+ )
159
+
160
+
161
+ # Add trace with large markers
162
+ fig.add_trace(
163
+ go.Scatter(
164
+ mode='markers',
165
+ x=[2, 2],
166
+ y=[4.25, 4.75],
167
+ marker=dict(
168
+ color='LightSkyBlue',
169
+ size=80,
170
+ opacity=0.5,
171
+ line=dict(
172
+ color='MediumPurple',
173
+ width=8
174
+ )
175
+ ),
176
+ showlegend=False
177
+ )
178
+ )
179
+
180
+ return fig, "Marker Opacity"
181
+
182
+ def fig3ter():
183
+ x = np.random.uniform(low=3, high=6, size=(500,))
184
+ y = np.random.uniform(low=3, high=6, size=(500,))
185
+
186
+
187
+ # Build figure
188
+ fig = go.Figure()
189
+
190
+ # Add scatter trace with medium sized markers
191
+ fig.add_trace(
192
+ go.Scatter(
193
+ mode='markers',
194
+ x=x,
195
+ y=y,
196
+ marker=dict(
197
+ color='rgba(135, 206, 250, 0.5)',
198
+ size=20,
199
+ line=dict(
200
+ color='MediumPurple',
201
+ width=2
202
+ )
203
+ ),
204
+ showlegend=False
205
+ )
206
+ )
207
+
208
+
209
+ # Add trace with large markers
210
+ fig.add_trace(
211
+ go.Scatter(
212
+ mode='markers',
213
+ x=[2, 2],
214
+ y=[4.25, 4.75],
215
+ marker=dict(
216
+ color='rgba(135, 206, 250, 0.5)',
217
+ size=80,
218
+ line=dict(
219
+ color='MediumPurple',
220
+ width=8
221
+ )
222
+ ),
223
+ showlegend=False
224
+ )
225
+ )
226
+ return fig, "Color opacity"
227
+
228
+ def fig4():
229
+ warn("This example is not exactly the one online, but has been changed as this kind of data is not yet supported.")
230
+ raw_symbols = SymbolValidator().values
231
+ namestems = []
232
+ namevariants = []
233
+ symbols = []
234
+ names = []
235
+ for i in range(0, len(raw_symbols), 3):
236
+ name = raw_symbols[i+2]
237
+ symbols.append(raw_symbols[i])
238
+ namestems.append(name.replace("-open", "").replace("-dot", ""))
239
+ namevariants.append(name[len(namestems[-1]):])
240
+ names.append(name)
241
+
242
+ fig = go.Figure()
243
+
244
+ i = 0
245
+
246
+ names = ["circle", "square", "diamond", "cross", "x", "triangle-up", "triangle-down", "triangle-left", "triangle-right", "triangle-ne", "triangle-se", "triangle-sw", "triangle-nw", "pentagon", "hexagon", "hexagon2", "octagon", "star", "hexagram", "star-triangle-up", "star-triangle-down", "star-square", "star-diamond", "diamond-tall", "diamond-wide", "hourglass", "bowtie", "circle-cross", "circle-x", "square-cross", "square-x", "diamond-cross", "diamond-x", "cross-thin", "x-thin", "asterisk", "hash", "y-up", "y-down", "y-left", "y-right", "line-ew", "line-ns", "line-ne", "line-nw", "arrow-up", "arrow-down", "arrow-left", "arrow-right", "arrow-bar-up", "arrow-bar-down", "arrow-bar-left", "arrow-bar-right", "arrow", "arrow-wide"]
247
+ types = ["", "-open"]
248
+ for name in names:
249
+ for type in types:
250
+ name = name + type
251
+ fig.add_trace(go.Scatter(mode="markers", x=[i%2], y=[-(i//2)], marker_symbol=name,
252
+ marker_line_color="midnightblue", marker_color="lightskyblue",
253
+ marker_line_width=2, marker_size=8,
254
+ showlegend=False,
255
+ hovertemplate="name: %{y}%{x}<br>number: %{marker.symbol}<extra></extra>"))
256
+ i += 1
257
+
258
+ fig.update_layout(
259
+ xaxis=dict(
260
+ tickmode='array',
261
+ tickvals=[0, 1],
262
+ ticktext=types
263
+ ),
264
+ yaxis=dict(
265
+ tickmode='array',
266
+ tickvals=list(range(0, -55, -1)),
267
+ ticktext=names
268
+ )
269
+ )
270
+
271
+ # fig.show()
272
+ return fig, "Custom Marker Symbols"
273
+
274
+
275
+ def fig5():
276
+ df = px.data.iris()
277
+ fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
278
+
279
+ fig.update_traces(
280
+ marker=dict(size=8, symbol="diamond", line=dict(width=2, color="DarkSlateGrey")),
281
+ selector=dict(mode="markers"),
282
+ )
283
+
284
+ return fig, "Using a custom marker "
285
+
286
+ def fig6():
287
+ df = px.data.iris()
288
+ fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
289
+
290
+ fig.update_traces(
291
+ marker=dict(
292
+ size=8,
293
+ symbol="diamond-open",
294
+ line=dict(
295
+ width=2,
296
+ # color="DarkSlateGrey" Line colors don't apply to open markers
297
+ )
298
+ ),
299
+ selector=dict(mode="markers"),
300
+ )
301
+ return fig, "Open Marker Colors"
302
+
303
+
304
+ def fig7():
305
+ df = px.data.iris()
306
+ fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
307
+
308
+ fig.update_traces(
309
+ marker=dict(
310
+ size=12, symbol="triangle-up", angle=45, line=dict(width=2, color="DarkSlateGrey")
311
+ ),
312
+ selector=dict(mode="markers"),
313
+ )
314
+ return fig, "Setting marker angle"
315
+
316
+ def fig8():
317
+ df = px.data.gapminder()
318
+ fig = go.Figure()
319
+
320
+ for x in df.loc[df.continent.isin(["Europe"])].country.unique()[:5]:
321
+ fil = df.loc[(df.country.str.contains(x))]
322
+ fig.add_trace(
323
+ go.Scatter(
324
+ x=fil["year"],
325
+ y=fil["pop"],
326
+ mode="lines+markers",
327
+ marker=dict(
328
+ symbol="arrow",
329
+ size=15,
330
+ angleref="previous",
331
+ ),
332
+ name=x,
333
+ )
334
+ )
335
+ return fig, "Setting Angle Reference"
336
+
337
+
338
+
339
+ if __name__ == "__main__":
340
+
341
+ print("Tikzploty : ", tikzplotly.__version__)
342
+ print("Plotly : ", plotly.__version__)
343
+ print("Test markers")
344
+
345
+
346
+ file_directory = os.path.dirname(os.path.abspath(__file__))
347
+
348
+ functions = [
349
+ ("1", fig1),
350
+ ("2", fig2),
351
+ ("3", fig3),
352
+ ("3bis", fig3bis),
353
+ # ("3ter", fig3ter),
354
+ ("5", fig5),
355
+ ("6", fig6),
356
+ ("7", fig7),
357
+ # ("8", fig8), # angle reference not supported yet
358
+ ]
359
+
360
+ main_tex_content = tex_create_document(options="twocolumn", compatibility="newest")
361
+ main_tex_content += "\\usepackage[left=1cm, right=1cm, top=1cm, bottom=1cm]{geometry}\n"
362
+ main_tex_content += "\n"
363
+ stack_env = []
364
+ main_tex_content += tex_begin_environment("document", stack_env) + '\n'
365
+
366
+ for i, f in functions:
367
+ print(f"Figure {i}")
368
+ fig, title = f()
369
+ data = fig.data
370
+ save_path = os.path.join(file_directory, "outputs", "test_markers", "fig{}.tex".format(i))
371
+ tikzplotly.save(save_path, fig)
372
+ main_tex_content += tex_begin_environment("figure", stack_env)
373
+ main_tex_content += " \\input{fig" + str(i) + ".tex}\n"
374
+ main_tex_content += " \\caption{" + title + "}\n"
375
+ main_tex_content += tex_end_environment(stack_env) + '\n'
376
+
377
+ main_tex_content += "\n" + tex_end_all_environment(stack_env)
378
+
379
+ main_tex_path = os.path.join(file_directory, "outputs", "test_markers", "main.tex")
380
+ print("Save main tex file : ", main_tex_path)
381
+ with open(main_tex_path, "w") as f:
382
+ f.write(main_tex_content)
383
+
384
+ ## Separately handling the case with all markers types
385
+ tex_markers = tex_create_document(document_class="standalone")
386
+ tex_markers += tex_begin_environment("document", stack_env) + '\n'
387
+ fig, title = fig4()
388
+ tikzplotly.save(os.path.join(file_directory, "outputs", "test_markers", "markers_fig.tex"), fig, axis_options="height=35cm, ymajorgrids, width=5cm")
389
+ tex_markers += "\\input{markers_fig.tex}\n"
390
+ tex_markers += tex_end_all_environment(stack_env)
391
+ with open(os.path.join(file_directory, "outputs", "test_markers", "markers.tex"), "w") as f:
392
+ f.write(tex_markers)
@@ -0,0 +1 @@
1
+ __version__ = "0.1.4"