Skip to content

Commit 350dde5

Browse files
committed
respect ellipse rotation
Fixes #256.
1 parent b1cbcd3 commit 350dde5

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

matplotlib2tikz/patch.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ def _draw_ellipse(data, obj, draw_options):
124124
return _draw_circle(data, obj, draw_options)
125125
x, y = obj.center
126126
ff = data["float format"]
127+
128+
if obj.angle != 0:
129+
fmt = "rotate around={{" + ff + ":(axis cs:" + ff + "," + ff + ")}}"
130+
draw_options.append(fmt.format(obj.angle, x, y))
131+
127132
cont = (
128133
"\\draw[{}] (axis cs:"
129134
+ ff

test/test_rotated_ellipse.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
import matplotlib.pyplot as plt
4+
from matplotlib.patches import Ellipse
5+
6+
from helpers import assert_equality
7+
8+
9+
def plot():
10+
fig = plt.figure()
11+
12+
x = 1.0
13+
y = 1.0
14+
15+
plt.plot(x, y, "ro")
16+
17+
ellip = Ellipse(
18+
xy=[x, y], width=16.0, height=4.0, angle=-160, alpha=0.5, color="green"
19+
)
20+
ax = plt.gca()
21+
ax.add_artist(ellip)
22+
23+
plt.xlim([-9, 10])
24+
plt.ylim([-3, 5])
25+
return fig
26+
27+
28+
def test():
29+
assert_equality(plot, __file__[:-3] + "_reference.tex")
30+
return
31+
32+
33+
if __name__ == "__main__":
34+
import helpers
35+
36+
helpers.compare_mpl_latex(plot)
37+
# helpers.print_tree(plot())
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
\begin{tikzpicture}
2+
3+
\begin{axis}[
4+
tick align=outside,
5+
tick pos=left,
6+
x grid style={white!69.01960784313725!black},
7+
xmin=-9, xmax=10,
8+
y grid style={white!69.01960784313725!black},
9+
ymin=-3, ymax=5
10+
]
11+
\draw[draw=green!50.19607843137255!black,fill=green!50.19607843137255!black,opacity=0.5,rotate around={-160:(axis cs:1,1)}] (axis cs:1,1) ellipse (8 and 2);
12+
\addplot [semithick, red, mark=*, mark size=3, mark options={solid}, only marks]
13+
table {%
14+
1 1
15+
};
16+
\end{axis}
17+
18+
\end{tikzpicture}

0 commit comments

Comments
 (0)