tikzplotly 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl
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.
- tests/test_bars.py +310 -0
- tests/test_line_charts.py +27 -1
- tests/test_markers.py +3 -2
- tests/test_polar.py +656 -0
- tests/test_scatter3d.py +138 -0
- tikzplotly/__about__.py +7 -1
- tikzplotly/__init__.py +12 -2
- tikzplotly/_annotations.py +18 -7
- tikzplotly/_axis.py +45 -18
- tikzplotly/_bar.py +94 -0
- tikzplotly/_color.py +94 -29
- tikzplotly/_dash.py +4 -1
- tikzplotly/_data.py +38 -10
- tikzplotly/_data_container.py +226 -0
- tikzplotly/_heatmap.py +14 -7
- tikzplotly/_histogram.py +45 -21
- tikzplotly/_marker.py +20 -0
- tikzplotly/_polar.py +216 -0
- tikzplotly/_save.py +122 -23
- tikzplotly/_scatter.py +30 -55
- tikzplotly/_scatter3d.py +75 -0
- tikzplotly/_tex.py +35 -19
- tikzplotly/_trace_utils.py +70 -0
- tikzplotly/_utils.py +88 -44
- {tikzplotly-0.2.0.dist-info → tikzplotly-0.2.2.dist-info}/METADATA +17 -11
- tikzplotly-0.2.2.dist-info/RECORD +31 -0
- {tikzplotly-0.2.0.dist-info → tikzplotly-0.2.2.dist-info}/WHEEL +1 -1
- tikzplotly/_dataContainer.py +0 -91
- tikzplotly-0.2.0.dist-info/RECORD +0 -24
- {tikzplotly-0.2.0.dist-info → tikzplotly-0.2.2.dist-info/licenses}/LICENSE +0 -0
- {tikzplotly-0.2.0.dist-info → tikzplotly-0.2.2.dist-info}/top_level.txt +0 -0
tests/test_bars.py
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# From https://plotly.com/python/bar-charts/ and https://plotly.com/python/horizontal-bar-charts/
|
|
2
|
+
import plotly
|
|
3
|
+
import plotly.express as px
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import plotly.graph_objects as go
|
|
6
|
+
from plotly.subplots import make_subplots
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
import tikzplotly
|
|
10
|
+
import os
|
|
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 fig_vertical1():
|
|
15
|
+
|
|
16
|
+
data_canada = px.data.gapminder().query("country == 'Canada'")
|
|
17
|
+
fig = px.bar(data_canada, x='year', y='pop')
|
|
18
|
+
|
|
19
|
+
# fig.show()
|
|
20
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig1.png"))
|
|
21
|
+
|
|
22
|
+
return fig, "Bar chart with Plotly Express"
|
|
23
|
+
|
|
24
|
+
def fig_vertical2():
|
|
25
|
+
|
|
26
|
+
long_df = px.data.medals_long()
|
|
27
|
+
|
|
28
|
+
fig = px.bar(long_df, x="nation", y="count", color="medal", title="Long-Form Input")
|
|
29
|
+
|
|
30
|
+
# fig.show()
|
|
31
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig2.png"))
|
|
32
|
+
|
|
33
|
+
return fig, "Bar charts with Long Format Data"
|
|
34
|
+
|
|
35
|
+
def fig_vertical3():
|
|
36
|
+
|
|
37
|
+
wide_df = px.data.medals_wide()
|
|
38
|
+
fig = px.bar(
|
|
39
|
+
wide_df,
|
|
40
|
+
x="nation",
|
|
41
|
+
y=["gold", "silver", "bronze"],
|
|
42
|
+
title="Wide-Form Input",
|
|
43
|
+
color_discrete_map={
|
|
44
|
+
"gold": "gold",
|
|
45
|
+
"silver": "silver",
|
|
46
|
+
"bronze": "#cd7f32"
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
fig.update_traces(marker_line_width=2, marker_line_color="black")
|
|
50
|
+
# fig.show()
|
|
51
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig3.png"))
|
|
52
|
+
|
|
53
|
+
return fig, "Bar charts with Wide Format Data"
|
|
54
|
+
|
|
55
|
+
def fig_vertical5():
|
|
56
|
+
|
|
57
|
+
df = px.data.gapminder().query("country == 'Canada'")
|
|
58
|
+
fig = px.bar(df, x='year', y='pop',
|
|
59
|
+
hover_data=['lifeExp', 'gdpPercap'], color='lifeExp',
|
|
60
|
+
labels={'pop':'population of Canada'}, height=400)
|
|
61
|
+
|
|
62
|
+
# fig.show()
|
|
63
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig5.png"))
|
|
64
|
+
|
|
65
|
+
return fig, "Colored Bars"
|
|
66
|
+
|
|
67
|
+
def fig_vertical6():
|
|
68
|
+
|
|
69
|
+
df = px.data.gapminder().query("continent == 'Oceania'")
|
|
70
|
+
fig = px.bar(df, x='year', y='pop',
|
|
71
|
+
hover_data=['lifeExp', 'gdpPercap'], color='country',
|
|
72
|
+
labels={'pop':'population of Canada'}, height=400)
|
|
73
|
+
|
|
74
|
+
# fig.show()
|
|
75
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig5bis.png"))
|
|
76
|
+
|
|
77
|
+
return fig, "Colored Bars"
|
|
78
|
+
|
|
79
|
+
def fig_vertical7():
|
|
80
|
+
|
|
81
|
+
df = px.data.tips()
|
|
82
|
+
fig = px.bar(df, x="sex", y="total_bill", color='time')
|
|
83
|
+
|
|
84
|
+
# fig.show()
|
|
85
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig6.png"))
|
|
86
|
+
|
|
87
|
+
return fig, "Stacked vs Grouped Bars"
|
|
88
|
+
|
|
89
|
+
def fig_vertical8():
|
|
90
|
+
|
|
91
|
+
df = px.data.tips()
|
|
92
|
+
fig = px.bar(df, x="sex", y="total_bill",
|
|
93
|
+
color='smoker', barmode='group',
|
|
94
|
+
height=400)
|
|
95
|
+
|
|
96
|
+
# fig.show()
|
|
97
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig6bis.png"))
|
|
98
|
+
|
|
99
|
+
return fig, "Stacked vs Grouped Bars"
|
|
100
|
+
|
|
101
|
+
def fig_vertical9():
|
|
102
|
+
|
|
103
|
+
df = px.data.tips()
|
|
104
|
+
fig = px.histogram(df, x="sex", y="total_bill",
|
|
105
|
+
color='smoker', barmode='group',
|
|
106
|
+
height=400)
|
|
107
|
+
|
|
108
|
+
# fig.show()
|
|
109
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig7.png"))
|
|
110
|
+
|
|
111
|
+
return fig, "Aggregating into Single Colored Bars"
|
|
112
|
+
|
|
113
|
+
def fig_vertical10():
|
|
114
|
+
|
|
115
|
+
df = px.data.tips()
|
|
116
|
+
fig = px.histogram(df, x="sex", y="total_bill",
|
|
117
|
+
color='smoker', barmode='group',
|
|
118
|
+
histfunc='avg',
|
|
119
|
+
height=400)
|
|
120
|
+
|
|
121
|
+
# fig.show()
|
|
122
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig7bis.png"))
|
|
123
|
+
|
|
124
|
+
return fig, "Aggregating into Single Colored Bars"
|
|
125
|
+
|
|
126
|
+
def fig_vertical11():
|
|
127
|
+
|
|
128
|
+
df = px.data.medals_long()
|
|
129
|
+
|
|
130
|
+
fig = px.bar(df, x="medal", y="count", color="nation", text_auto=True)
|
|
131
|
+
|
|
132
|
+
# fig.show()
|
|
133
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig8.png"))
|
|
134
|
+
|
|
135
|
+
return fig, "Bar Charts with Text"
|
|
136
|
+
|
|
137
|
+
def fig_vertical12():
|
|
138
|
+
|
|
139
|
+
df = px.data.medals_long()
|
|
140
|
+
|
|
141
|
+
fig = px.bar(df, x="medal", y="count", color="nation", text="nation")
|
|
142
|
+
|
|
143
|
+
# fig.show()
|
|
144
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig8bis.png"))
|
|
145
|
+
|
|
146
|
+
return fig, "Bar Charts with Text"
|
|
147
|
+
|
|
148
|
+
def fig_vertical13():
|
|
149
|
+
|
|
150
|
+
df = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6")
|
|
151
|
+
fig = px.bar(df, y='pop', x='country', text_auto='.2s',
|
|
152
|
+
title="Default: various text sizes, positions and angles")
|
|
153
|
+
|
|
154
|
+
# fig.show()
|
|
155
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig8ter.png"))
|
|
156
|
+
|
|
157
|
+
return fig, "Bar Charts with Text"
|
|
158
|
+
|
|
159
|
+
def fig_vertical14():
|
|
160
|
+
|
|
161
|
+
df = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6")
|
|
162
|
+
fig = px.bar(df, y='pop', x='country', text_auto='.2s',
|
|
163
|
+
title="Controlled text sizes, positions and angles")
|
|
164
|
+
fig.update_traces(textfont_size=12, textangle=0, textposition="outside", cliponaxis=False)
|
|
165
|
+
|
|
166
|
+
# fig.show()
|
|
167
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig8quater.png"))
|
|
168
|
+
|
|
169
|
+
return fig, "Bar Charts with Text"
|
|
170
|
+
|
|
171
|
+
def fig_vertical15():
|
|
172
|
+
|
|
173
|
+
df = px.data.medals_long()
|
|
174
|
+
|
|
175
|
+
fig = px.bar(df, x="medal", y="count", color="nation",
|
|
176
|
+
pattern_shape="nation", pattern_shape_sequence=[".", "x", "+"])
|
|
177
|
+
|
|
178
|
+
# fig.show()
|
|
179
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig9.png"))
|
|
180
|
+
|
|
181
|
+
return fig, "Pattern fills"
|
|
182
|
+
|
|
183
|
+
def fig_vertical16():
|
|
184
|
+
animals=['giraffes', 'orangutans', 'monkeys']
|
|
185
|
+
|
|
186
|
+
fig = go.Figure([go.Bar(x=animals, y=[20, 14, 23])])
|
|
187
|
+
|
|
188
|
+
# fig.show()
|
|
189
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig10.png"))
|
|
190
|
+
|
|
191
|
+
return fig, "Basic Bar Charts with plotly graph objects"
|
|
192
|
+
|
|
193
|
+
def fig_vertical17():
|
|
194
|
+
animals=['giraffes', 'orangutans', 'monkeys']
|
|
195
|
+
|
|
196
|
+
fig = go.Figure(data=[
|
|
197
|
+
go.Bar(name='SF Zoo', x=animals, y=[20, 14, 23]),
|
|
198
|
+
go.Bar(name='LA Zoo', x=animals, y=[12, 18, 29])
|
|
199
|
+
])
|
|
200
|
+
# Change the bar mode
|
|
201
|
+
fig.update_layout(barmode='group')
|
|
202
|
+
|
|
203
|
+
# fig.show()
|
|
204
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig11.png"))
|
|
205
|
+
|
|
206
|
+
return fig, "Grouped Bar Chart"
|
|
207
|
+
|
|
208
|
+
def fig_vertical18():
|
|
209
|
+
animals=['giraffes', 'orangutans', 'monkeys']
|
|
210
|
+
|
|
211
|
+
fig = go.Figure(data=[
|
|
212
|
+
go.Bar(name='SF Zoo', x=animals, y=[20, 14, 23]),
|
|
213
|
+
go.Bar(name='LA Zoo', x=animals, y=[12, 18, 29])
|
|
214
|
+
])
|
|
215
|
+
# Change the bar mode
|
|
216
|
+
fig.update_layout(barmode='stack')
|
|
217
|
+
|
|
218
|
+
# fig.show()
|
|
219
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig12.png"))
|
|
220
|
+
|
|
221
|
+
return fig, "Stacked Bar Chart"
|
|
222
|
+
|
|
223
|
+
def fig_vertical19():
|
|
224
|
+
x = [1, 2, 3, 4]
|
|
225
|
+
|
|
226
|
+
fig = go.Figure()
|
|
227
|
+
fig.add_trace(go.Bar(x=x, y=[1, 4, 9, 16]))
|
|
228
|
+
fig.add_trace(go.Bar(x=x, y=[6, -8, -4.5, 8]))
|
|
229
|
+
fig.add_trace(go.Bar(x=x, y=[-15, -3, 4.5, -8]))
|
|
230
|
+
fig.add_trace(go.Bar(x=x, y=[-1, 3, -3, -4]))
|
|
231
|
+
|
|
232
|
+
fig.update_layout(barmode='relative', title_text='Relative Barmode')
|
|
233
|
+
|
|
234
|
+
# fig.show()
|
|
235
|
+
# fig.write_image(os.path.join(file_directory, "outputs", "test_bars", "fig13.png"))
|
|
236
|
+
|
|
237
|
+
return fig, "Bar Chart with Relative Barmode"
|
|
238
|
+
|
|
239
|
+
def fig_horizontal1():
|
|
240
|
+
df = px.data.tips()
|
|
241
|
+
fig = px.bar(df, x="total_bill", y="day", orientation='h')
|
|
242
|
+
return fig, "Horizontal figure"
|
|
243
|
+
|
|
244
|
+
def fig_horizontal2():
|
|
245
|
+
fig = go.Figure(go.Bar(
|
|
246
|
+
x=[20, 14, 23],
|
|
247
|
+
y=['giraffes', 'orangutans', 'monkeys'],
|
|
248
|
+
orientation='h'))
|
|
249
|
+
return fig, "Basic Horizontal Bar Chart"
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
if __name__ == "__main__":
|
|
253
|
+
|
|
254
|
+
print("Tikzploty : ", tikzplotly.__version__)
|
|
255
|
+
print("Plotly : ", plotly.__version__)
|
|
256
|
+
print("Test histograms")
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
file_directory = os.path.dirname(os.path.abspath(__file__))
|
|
260
|
+
|
|
261
|
+
functions = [
|
|
262
|
+
("vertical1", fig_vertical1),
|
|
263
|
+
("vertical2", fig_vertical2),
|
|
264
|
+
("vertical3", fig_vertical3),
|
|
265
|
+
("vertical5", fig_vertical5),
|
|
266
|
+
("vertical6", fig_vertical6),
|
|
267
|
+
("vertical7", fig_vertical7), # Stacked bars are not supported yet.
|
|
268
|
+
("vertical8", fig_vertical8), # Stacked bars are not supported yet.
|
|
269
|
+
("vertical9", fig_vertical9), # Aggregated bars are not supported yet.
|
|
270
|
+
("vertical10", fig_vertical10), # Aggregated bars are not supported yet.
|
|
271
|
+
("vertical11", fig_vertical11), # Text template is not supported yet.
|
|
272
|
+
("vertical12", fig_vertical12), # Text template is not supported yet.
|
|
273
|
+
("vertical13", fig_vertical13), # Text template is not supported yet.
|
|
274
|
+
("vertical14", fig_vertical14), # Text template is not supported yet.
|
|
275
|
+
("vertical15", fig_vertical15), # Pattern fills are not supported yet.
|
|
276
|
+
("vertical16", fig_vertical16),
|
|
277
|
+
("vertical17", fig_vertical17),
|
|
278
|
+
("vertical18", fig_vertical18),
|
|
279
|
+
("vertical19", fig_vertical19),
|
|
280
|
+
("horizontal1", fig_horizontal1),
|
|
281
|
+
("horizontal2", fig_horizontal2),
|
|
282
|
+
]
|
|
283
|
+
|
|
284
|
+
main_tex_content = tex_create_document(options="twocolumn", compatibility="newest")
|
|
285
|
+
main_tex_content += "\\usepackage[left=1cm, right=1cm, top=1cm, bottom=1cm]{geometry}\n"
|
|
286
|
+
main_tex_content += "\n"
|
|
287
|
+
stack_env = []
|
|
288
|
+
main_tex_content += tex_begin_environment("document", stack_env) + '\n'
|
|
289
|
+
|
|
290
|
+
output_path = os.path.join(file_directory, "outputs", "test_bars")
|
|
291
|
+
if not os.path.exists(output_path):
|
|
292
|
+
os.makedirs(output_path)
|
|
293
|
+
|
|
294
|
+
for i, f in functions:
|
|
295
|
+
print(f"Figure {i}")
|
|
296
|
+
fig, title = f()
|
|
297
|
+
data = fig.data
|
|
298
|
+
save_path = os.path.join(file_directory, "outputs", "test_bars", "fig{}.tex".format(i))
|
|
299
|
+
tikzplotly.save(save_path, fig)
|
|
300
|
+
main_tex_content += tex_begin_environment("figure", stack_env)
|
|
301
|
+
main_tex_content += " \\input{fig" + str(i) + ".tex}\n"
|
|
302
|
+
main_tex_content += " \\caption{" + title + "}\n"
|
|
303
|
+
main_tex_content += tex_end_environment(stack_env) + '\n'
|
|
304
|
+
|
|
305
|
+
main_tex_content += "\n" + tex_end_all_environment(stack_env)
|
|
306
|
+
|
|
307
|
+
main_tex_path = os.path.join(file_directory, "outputs", "test_bars", "main.tex")
|
|
308
|
+
print("Save main tex file : ", main_tex_path)
|
|
309
|
+
with open(main_tex_path, "w") as f:
|
|
310
|
+
f.write(main_tex_content)
|
tests/test_line_charts.py
CHANGED
|
@@ -394,6 +394,29 @@ def fig18():
|
|
|
394
394
|
fig.update_xaxes(minor=dict(ticks="inside", ticklen=6, showgrid=True))
|
|
395
395
|
return fig, "Log scale with range and minor ticks"
|
|
396
396
|
|
|
397
|
+
def fig19():
|
|
398
|
+
df = pd.DataFrame(dict(
|
|
399
|
+
x = ["A et B", "B", "C", "D"],
|
|
400
|
+
y = [1, 2, 3, 4],
|
|
401
|
+
))
|
|
402
|
+
fig = px.line(df, x="x", y="y", title="symbolic x coords")
|
|
403
|
+
return fig, "Line Charts with symbolic x coords"
|
|
404
|
+
|
|
405
|
+
def fig20():
|
|
406
|
+
df = pd.DataFrame(dict(
|
|
407
|
+
x = [1, 2, 3, 4],
|
|
408
|
+
y = ["A", "B", "C", "D"],
|
|
409
|
+
))
|
|
410
|
+
fig = px.line(df, x="x", y="y", title="symbolic y coords")
|
|
411
|
+
return fig, "Line Charts with symbolic y coords"
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def fig21(x=True, y=False):
|
|
415
|
+
fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
|
|
416
|
+
if x: fig.data[0].x = None
|
|
417
|
+
if y: fig.data[0].y = None
|
|
418
|
+
return fig, "empty fig"
|
|
419
|
+
|
|
397
420
|
if __name__ == "__main__":
|
|
398
421
|
|
|
399
422
|
print("Tikzploty : ", tikzplotly.__version__)
|
|
@@ -414,12 +437,15 @@ if __name__ == "__main__":
|
|
|
414
437
|
("9", fig9),
|
|
415
438
|
("10", fig10),
|
|
416
439
|
("11", fig11),
|
|
417
|
-
|
|
440
|
+
("12", fig12),
|
|
418
441
|
("14", fig14),
|
|
419
442
|
("15", fig15),
|
|
420
443
|
("16", fig16),
|
|
421
444
|
("17", fig17),
|
|
422
445
|
("18", fig18),
|
|
446
|
+
("19", fig19),
|
|
447
|
+
("20", fig20),
|
|
448
|
+
("21", fig21),
|
|
423
449
|
]
|
|
424
450
|
|
|
425
451
|
main_tex_content = tex_create_document(options="twocolumn", compatibility="newest")
|
tests/test_markers.py
CHANGED
|
@@ -6,7 +6,7 @@ import numpy as np
|
|
|
6
6
|
import tikzplotly
|
|
7
7
|
import os
|
|
8
8
|
import plotly.graph_objects as go
|
|
9
|
-
from plotly.
|
|
9
|
+
from plotly.validator_cache import ValidatorCache
|
|
10
10
|
from warnings import warn
|
|
11
11
|
from tikzplotly._tex import tex_create_document, tex_begin_environment, tex_end_environment, tex_end_all_environment
|
|
12
12
|
|
|
@@ -226,7 +226,8 @@ def fig3ter():
|
|
|
226
226
|
|
|
227
227
|
def fig4():
|
|
228
228
|
warn("This example is not exactly the one online, but has been changed as this kind of data is not yet supported.")
|
|
229
|
-
|
|
229
|
+
SymbolValidator = ValidatorCache.get_validator("scatter.marker", "symbol")
|
|
230
|
+
raw_symbols = SymbolValidator.values
|
|
230
231
|
namestems = []
|
|
231
232
|
namevariants = []
|
|
232
233
|
symbols = []
|