在matplotlib中绘制非正交轴? [英] Draw non-orthogonal axis in matplotlib?

查看:62
本文介绍了在matplotlib中绘制非正交轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to draw a Minkowski diagram. It includes two different axis, one for each system, they are, however, not all orthogonal. Is there a way to plot a pair of axis for one system non-orthogonal?

推荐答案

这是一个使用 AxisArtistGridHelperCurveLinear,它是从此处修改的.

Here's an example using AxisArtist and GridHelperCurveLinear, which is modified from 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中绘制非正交轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆