gpt4 book ai didi

matplotlib - 在matplotlib中绘制非正交轴?

转载 作者:行者123 更新时间:2023-12-05 01:04:09 24 4
gpt4 key购买 nike

我想画一个闵可夫斯基图。
它包括两个不同的轴,每个系统一个,但它们并非都是正交的。有没有办法为一个非正交系统绘制一对轴?

最佳答案

这是使用 AxisArtist 的示例和 GridHelperCurveLinear , 修改自 here .

enter image description here

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

def curvelinear_test1(fig):
def tr(x, y):
x, y = np.asarray(x), np.asarray(y)
return .8*x+.2*y, .2*x + .8*y
def inv_tr(x,y):
x, y = np.asarray(x), np.asarray(y)
return 1.333*x + -.333*y, -.333*x + 1.333*y

grid_helper = GridHelperCurveLinear((tr, inv_tr))
ax1 = Subplot(fig, 1, 1, 1, grid_helper=grid_helper)
fig.add_subplot(ax1)

xx, yy = tr([3, 6], [5.0, 10.])
ax1.plot(xx, yy)

ax1.set_aspect(1.)
ax1.set_xlim(-10, 10.)
ax1.set_ylim(-10, 10.)

ax1.axis["t"]=ax1.new_floating_axis(0, 0.)
ax1.axis["t2"]=ax1.new_floating_axis(1, 0.)
ax1.grid(True)

fig = plt.figure()
curvelinear_test1(fig)
plt.show()

关于matplotlib - 在matplotlib中绘制非正交轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23581073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com