【问题标题】:Draw non-orthogonal axis in matplotlib?在matplotlib中绘制非正交轴?
【发布时间】:2014-06-28 03:58:00
【问题描述】:

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

【问题讨论】:

标签: matplotlib


【解决方案1】:

这是一个使用AxisArtistGridHelperCurveLinear 的示例,它是从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()

【讨论】:

  • 效果很好!很高兴你花时间回答问题这么好!谢谢!
  • @andi:很高兴它对你有用。顺便说一句,我编辑了这个。我之前所拥有的在数学上是正确的,但可能与您想要的物理不匹配,因为我在转换后的轴上切换了 x 和 y。之前我有x'=.2x+.8y,现在我有x'=.8x+.2y;也就是说,相对速度会在空间中增加一点时间,但不会交换它们。
  • ;) 我设法从示例中得出它。所以它工作得很快。感谢您也将其添加到帖子中。让它更有价值!
猜你喜欢
  • 2013-06-09
  • 1970-01-01
  • 2019-06-09
  • 2017-07-09
  • 2010-10-20
相关资源
最近更新 更多