No rotation of the contour plot in a non-orthogonal plot

Viewed 82

Here you can see an example where i try to add a contour plot in an existing plot. I want to rotate the the "horizontal" lines of the y-axis with the grid_helper. In the first image you can see that the horizontal lines of the y-axis are orthogonal without the grid_helper.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axisartist.grid_helper_curvelinear import GridHelperCurveLinear
from mpl_toolkits.axisartist import Subplot

# Define the range of x and y
x = np.linspace(0, 30, 100)
y = np.linspace(0, 30, 100)

# Generate a meshgrid
X, Y = np.meshgrid(x, y)

# Define z as a function of x and y
def z(x, y):
    return  x + y

# Use the grid_helper tool in order to turn the y axis from orthogonal to non-orthogonal
def tr(x, y):
    x, y = np.asarray(x), np.asarray(y)
    return x, -2.5 * x + y

def inv_tr(x, y):
    x, y = np.asarray(x), np.asarray(y)
    return 4 / 3 * x + -1 / 3 * y, x + 4 / 3 * y

grid_helper = GridHelperCurveLinear((tr, inv_tr))

# Adding a subplot and create a contour plot with X,Y and z(X,Y)
# This would be the contour plot in the figure with an orthogonal y-axis
fig = plt.figure(figsize=(25, 15))
ax1 = Subplot(fig, 1, 1, 1)

fig.add_subplot(ax1)
ax1.grid(visible=True, which="both", axis="y", linewidth=1)

ax1.contour(X, Y, z(X, Y))

plt.show()

The created plot should look like this:

[Contour plot in the orthogonal system]

Now i want to add the contour plot in the non-orthogonal system by implementing the grid helper in my Subplot.

the last few lines should look like this:

fig = plt.figure(figsize=(25, 15))

#Here I implement the grid_helper in the subplot
ax1 = Subplot(fig, 1, 1, 1, grid_helper=grid_helper)

fig.add_subplot(ax1)
ax1.grid(visible=True, which="both", axis="y", linewidth=1)

ax1.contour(X, Y, z(X, Y))

plt.show()

The second plot looks like this:

[Contour plot in the non-prthogonal system]

As you can see, the grid_helper had an effect on the "horizontal" lines of the y-axis but didn't rotate the lines of the contour plot. My Question is, if there is any way to rotate the contour plot lines like I did with the lines of the y-axis.

0 Answers
Related