将 Matplotlib/Seaborn 散点图变形为平行四边形

Warping Matplotlib/Seaborn Scatter Plot into Parallelogram

我有一个二维散点图(在 matplotlib 或 seaborn 中)和一个角度,例如64度。我想绘制此散点图的扭曲版本,其中第一个图的 x 轴保持固定但第二个轴被扭曲,使得第一个图的 y 轴现在与 x 轴成给定角度新情节(即 64 度)。我该怎么做?

换句话说,我想采用原始散点图并将 y 轴向右“推”以形成类似平行四边形的图,其中旧 y 轴与 old/new 之间的角度x轴是给定的角度。

这是对an old tutorial example的改编:

import matplotlib.pyplot as plt
from matplotlib.transforms import Affine2D
import mpl_toolkits.axisartist.floating_axes as floating_axes
import numpy as np

fig = plt.figure()
skewed_transform = Affine2D().skew_deg(90 - 64, 0)
grid_helper = floating_axes.GridHelperCurveLinear(skewed_transform, extremes=(-0.5, 1.5, -0.5, 1.5))
skewed_ax = floating_axes.FloatingSubplot(fig, 111, grid_helper=grid_helper)
skewed_ax.set_facecolor('0.95')  # light grey background
skewed_ax.axis["top"].set_visible(False)
skewed_ax.axis["right"].set_visible(False)
fig.add_subplot(skewed_ax)
x, y = np.random.rand(2, 100)  # random point in a square of [0,1]x[0,1]
skewed_ax.scatter(x, y, transform=skewed_transform + skewed_ax.transData)
plt.show()