tikzplotly 0.2.0__tar.gz → 0.2.1__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.
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/PKG-INFO +16 -11
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/README.md +12 -8
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/pyproject.toml +2 -2
- tikzplotly-0.2.1/src/tests/test_bars.py +310 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tests/test_line_charts.py +27 -1
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tests/test_markers.py +3 -2
- tikzplotly-0.2.1/src/tests/test_polar.py +656 -0
- tikzplotly-0.2.1/src/tests/test_scatter3d.py +138 -0
- tikzplotly-0.2.1/src/tikzplotly/__about__.py +7 -0
- tikzplotly-0.2.1/src/tikzplotly/__init__.py +14 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly/_annotations.py +18 -7
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly/_axis.py +45 -18
- tikzplotly-0.2.1/src/tikzplotly/_bar.py +94 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly/_color.py +88 -24
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly/_dash.py +4 -1
- tikzplotly-0.2.1/src/tikzplotly/_data.py +63 -0
- tikzplotly-0.2.1/src/tikzplotly/_dataContainer.py +226 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly/_heatmap.py +12 -6
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly/_histogram.py +34 -10
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly/_marker.py +20 -0
- tikzplotly-0.2.1/src/tikzplotly/_polar.py +216 -0
- tikzplotly-0.2.1/src/tikzplotly/_save.py +246 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly/_scatter.py +24 -19
- tikzplotly-0.2.1/src/tikzplotly/_scatter3d.py +104 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly/_tex.py +35 -19
- tikzplotly-0.2.1/src/tikzplotly/_utils.py +229 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly.egg-info/PKG-INFO +16 -11
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly.egg-info/SOURCES.txt +10 -0
- tikzplotly-0.2.1/tests/test_bars.py +57 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/tests/test_markers.py +18 -2
- tikzplotly-0.2.1/tests/test_polar.py +278 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/tests/test_scatter.py +18 -1
- tikzplotly-0.2.1/tests/test_scatter3d.py +100 -0
- tikzplotly-0.2.1/tests/test_specific.py +52 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/tests/test_tikzplotly.py +4 -3
- tikzplotly-0.2.0/src/tikzplotly/__about__.py +0 -1
- tikzplotly-0.2.0/src/tikzplotly/__init__.py +0 -4
- tikzplotly-0.2.0/src/tikzplotly/_data.py +0 -35
- tikzplotly-0.2.0/src/tikzplotly/_dataContainer.py +0 -91
- tikzplotly-0.2.0/src/tikzplotly/_save.py +0 -147
- tikzplotly-0.2.0/src/tikzplotly/_utils.py +0 -177
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/LICENSE +0 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/setup.cfg +0 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tests/test_heatmaps.py +0 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tests/test_histograms.py +0 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly.egg-info/dependency_links.txt +0 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly.egg-info/requires.txt +0 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/src/tikzplotly.egg-info/top_level.txt +0 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/tests/test_heatmap.py +0 -0
- {tikzplotly-0.2.0 → tikzplotly-0.2.1}/tests/test_histograms.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: tikzplotly
|
|
3
|
-
Version: 0.2.
|
|
4
|
-
Summary: Convert plotly figures to LaTeX /
|
|
3
|
+
Version: 0.2.1
|
|
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)
|
|
7
7
|
|
|
@@ -46,6 +46,7 @@ Requires-Dist: plotly
|
|
|
46
46
|
Requires-Dist: pillow
|
|
47
47
|
Provides-Extra: dev
|
|
48
48
|
Requires-Dist: pandas; extra == "dev"
|
|
49
|
+
Dynamic: license-file
|
|
49
50
|
|
|
50
51
|

|
|
51
52
|
|
|
@@ -57,17 +58,20 @@ Requires-Dist: pandas; extra == "dev"
|
|
|
57
58
|
|
|
58
59
|
[](https://github.com/thomas-saigre/tikzplotly/releases)
|
|
59
60
|
[](https://github.com/thomas-saigre/tikzplotly/issues)
|
|
60
|
-
[](https://codecov.io/gh/thomas-saigre/tikzplotly)
|
|
61
63
|

|
|
62
64
|
|
|
63
65
|
|
|
64
66
|
# Tikzplotly
|
|
65
67
|
|
|
66
|
-
Convert [plotly](https://plotly.com/python/) figures to
|
|
68
|
+
Convert [plotly](https://plotly.com/python/) figures to TikZ code for inclusion into [PGFPlots](https://www.ctan.org/pkg/pgfplots) ([PGF/TikZ](https://www.ctan.org/pkg/pgf)) figures.
|
|
67
69
|
|
|
68
70
|
This results in a ti*k*z code, that can be easily included into your LaTeX document.
|
|
69
71
|
This also allows to easily edit the content of the figure.
|
|
70
72
|
|
|
73
|
+
More details can be found in [the documentation](https://thomas-saigre.github.io/tikzplotly/).
|
|
74
|
+
|
|
71
75
|
## Example
|
|
72
76
|
|
|
73
77
|
The following Python code
|
|
@@ -84,7 +88,8 @@ tikzplotly.save("example.tex", fig)
|
|
|
84
88
|
will result in the following ti*k*z code
|
|
85
89
|
|
|
86
90
|
```latex
|
|
87
|
-
\pgfplotstableread{
|
|
91
|
+
\pgfplotstableread{
|
|
92
|
+
x Australia NewZealand
|
|
88
93
|
1952 69.12 69.39
|
|
89
94
|
1957 70.33 70.26
|
|
90
95
|
1962 70.93 71.24
|
|
@@ -97,7 +102,7 @@ will result in the following ti*k*z code
|
|
|
97
102
|
1997 78.83 77.55
|
|
98
103
|
2002 80.37 79.11
|
|
99
104
|
2007 81.235 80.204
|
|
100
|
-
}\
|
|
105
|
+
}\dataA
|
|
101
106
|
|
|
102
107
|
\begin{tikzpicture}
|
|
103
108
|
|
|
@@ -106,11 +111,11 @@ will result in the following ti*k*z code
|
|
|
106
111
|
|
|
107
112
|
\begin{axis}[
|
|
108
113
|
xlabel=year,
|
|
109
|
-
ylabel=lifeExp
|
|
114
|
+
ylabel=lifeExp
|
|
110
115
|
]
|
|
111
|
-
\addplot+ [mark=*, solid, color=636efa
|
|
116
|
+
\addplot+ [mark=*, solid, color=636efa] table[y=Australia] {\dataA};
|
|
112
117
|
\addlegendentry{Australia}
|
|
113
|
-
\addplot+ [mark=*, solid, color=EF553B
|
|
118
|
+
\addplot+ [mark=*, solid, color=EF553B] table[y=NewZealand] {\dataA};
|
|
114
119
|
\addlegendentry{New Zealand}
|
|
115
120
|
\end{axis}
|
|
116
121
|
\end{tikzpicture}
|
|
@@ -148,7 +153,7 @@ To correctly compile the document, you will need to add the following packages t
|
|
|
148
153
|
|
|
149
154
|
* 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.
|
|
150
155
|
You can also submit a pull request with the desired feature !
|
|
151
|
-
* Some feature can result in different output between the plotly figure and the
|
|
156
|
+
* Some feature can result in different output between the plotly figure and the TikZ figure, for instance the size of markers, more details can be found in [the documentation](https://thomas-saigre.github.io/tikzplotly/).
|
|
152
157
|
|
|
153
158
|
|
|
154
159
|
## References
|
|
@@ -8,17 +8,20 @@
|
|
|
8
8
|
|
|
9
9
|
[](https://github.com/thomas-saigre/tikzplotly/releases)
|
|
10
10
|
[](https://github.com/thomas-saigre/tikzplotly/issues)
|
|
11
|
-
[](https://codecov.io/gh/thomas-saigre/tikzplotly)
|
|
12
13
|

|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
# Tikzplotly
|
|
16
17
|
|
|
17
|
-
Convert [plotly](https://plotly.com/python/) figures to
|
|
18
|
+
Convert [plotly](https://plotly.com/python/) figures to TikZ code for inclusion into [PGFPlots](https://www.ctan.org/pkg/pgfplots) ([PGF/TikZ](https://www.ctan.org/pkg/pgf)) figures.
|
|
18
19
|
|
|
19
20
|
This results in a ti*k*z code, that can be easily included into your LaTeX document.
|
|
20
21
|
This also allows to easily edit the content of the figure.
|
|
21
22
|
|
|
23
|
+
More details can be found in [the documentation](https://thomas-saigre.github.io/tikzplotly/).
|
|
24
|
+
|
|
22
25
|
## Example
|
|
23
26
|
|
|
24
27
|
The following Python code
|
|
@@ -35,7 +38,8 @@ tikzplotly.save("example.tex", fig)
|
|
|
35
38
|
will result in the following ti*k*z code
|
|
36
39
|
|
|
37
40
|
```latex
|
|
38
|
-
\pgfplotstableread{
|
|
41
|
+
\pgfplotstableread{
|
|
42
|
+
x Australia NewZealand
|
|
39
43
|
1952 69.12 69.39
|
|
40
44
|
1957 70.33 70.26
|
|
41
45
|
1962 70.93 71.24
|
|
@@ -48,7 +52,7 @@ will result in the following ti*k*z code
|
|
|
48
52
|
1997 78.83 77.55
|
|
49
53
|
2002 80.37 79.11
|
|
50
54
|
2007 81.235 80.204
|
|
51
|
-
}\
|
|
55
|
+
}\dataA
|
|
52
56
|
|
|
53
57
|
\begin{tikzpicture}
|
|
54
58
|
|
|
@@ -57,11 +61,11 @@ will result in the following ti*k*z code
|
|
|
57
61
|
|
|
58
62
|
\begin{axis}[
|
|
59
63
|
xlabel=year,
|
|
60
|
-
ylabel=lifeExp
|
|
64
|
+
ylabel=lifeExp
|
|
61
65
|
]
|
|
62
|
-
\addplot+ [mark=*, solid, color=636efa
|
|
66
|
+
\addplot+ [mark=*, solid, color=636efa] table[y=Australia] {\dataA};
|
|
63
67
|
\addlegendentry{Australia}
|
|
64
|
-
\addplot+ [mark=*, solid, color=EF553B
|
|
68
|
+
\addplot+ [mark=*, solid, color=EF553B] table[y=NewZealand] {\dataA};
|
|
65
69
|
\addlegendentry{New Zealand}
|
|
66
70
|
\end{axis}
|
|
67
71
|
\end{tikzpicture}
|
|
@@ -99,7 +103,7 @@ To correctly compile the document, you will need to add the following packages t
|
|
|
99
103
|
|
|
100
104
|
* 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.
|
|
101
105
|
You can also submit a pull request with the desired feature !
|
|
102
|
-
* Some feature can result in different output between the plotly figure and the
|
|
106
|
+
* Some feature can result in different output between the plotly figure and the TikZ figure, for instance the size of markers, more details can be found in [the documentation](https://thomas-saigre.github.io/tikzplotly/).
|
|
103
107
|
|
|
104
108
|
|
|
105
109
|
## References
|
|
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tikzplotly"
|
|
7
|
-
version = "0.2.
|
|
8
|
-
description = "Convert plotly figures to LaTeX /
|
|
7
|
+
version = "0.2.1"
|
|
8
|
+
description = "Convert plotly figures to LaTeX / TikZ figures"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{name = "Thomas Saigre", email = "tikzplotly@outlook.fr"}]
|
|
11
11
|
license = { file = "LICENSE" }
|
|
@@ -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)
|
|
@@ -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")
|
|
@@ -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 = []
|