Let's say I want to draw an equilateral triangle. One way is simply to plot its vertices, which can be at say (0,0), (1,0) and (1/2,\sqrt(3)/2):
import matplotlib.pyplot as plt
from math import sqrt
figure, ax = plt.subplots()
ax.plot([0,1,1/2,0],[0,0,sqrt(3)/2,0],'k-')
ax.set_aspect('equal')
But supposing my y axis was tilted not at right angles to the x axis, but at 60 degrees. This means that the vertices in that system would be (0,0), (0,1), (1,0). I should be able to do this by some sort of affine transformation:
import matplotlib.pyplot as plt
from matplotlib.transforms import Affine2D
from math import sqrt
figure, ax = plt.subplots()
ax.plot([0,1,1,0],[0,0,1,0],'k-')
ax....
ax.set_aspect('equal')
where the sixth line would somehow transform the entire figure so that the right-angled triangle becomes equilateral. But try as I might with Affine2D
, I can't get it to work.
Another option - and I don't know if this would be possible in matplotlib - would be to redefine y so that (0,1) is mapped to (1/2, sqrt(3)/2).
Any help, or pointers to useful URLs would be great - thanks!