Python:如何使用matplotlib在套索图上绘制Pabon?

Python:如何使用matplotlib在套索图上绘制Pabon?,python,matplotlib,plot,Python,Matplotlib,Plot,我正在尝试使用python的matplotlib库绘制Pabon套索图。 Pabon Lasso是医疗服务效率/绩效图。 我仅在以下位置找到用于绘图的R代码库: 通过搜索,但我没有任何知识 Pabon套索图示例如下: X轴指的是BOR(床位占用率)。 Y轴指BTR(床周转率)。 顶部和右侧轴表示平均停留时间(ALOS) 图表分为四个象限,每个象限代表不同的效率/绩效水平。 图表中间的水平线是平均BTR。 图表中间的垂直线是平均出生率。 图表上的对角线为y/x=BTR/BOR的梯度。 每条对角

我正在尝试使用python的matplotlib库绘制Pabon套索图。 Pabon Lasso是医疗服务效率/绩效图。 我仅在以下位置找到用于绘图的R代码库: 通过搜索,但我没有任何知识

Pabon套索图示例如下:

X轴指的是BOR(床位占用率)。 Y轴指BTR(床周转率)。 顶部和右侧轴表示平均停留时间(ALOS)

图表分为四个象限,每个象限代表不同的效率/绩效水平。 图表中间的水平线是平均BTR。 图表中间的垂直线是平均出生率。 图表上的对角线为y/x=BTR/BOR的梯度。 每条对角线从原点开始。 右(或顶部)轴上的交点表示ALO

我尝试过使用下面的代码,但仍然停留在ALOS参数的顶部和右侧轴的标签上

我的代码:

import matplotlib.pyplot as plt
import numpy as np

#[2016, 2017]
BOR=[57.6, 52.03]
BTR=[69.81, 20.08]
ALOS = [4.04, 12.68]

mean_BTR = np.mean(BTR)
mean_BOR = np.mean(BOR)

fig=plt.figure()
ax=fig.add_subplot(111, label="1")
ax2=fig.add_subplot(111, label="2", frame_on=False)

#scatter points
ax.scatter([0, 57.6], [0, 52.03], color="C0")
ax.annotate('2016', (57.6 + 2, 52.03))
ax.scatter([0, 69.81], [0, 20.08], color="C0")
ax.annotate('2017', (69.81 - 5, 20.08+2))

#draw diagonals
ax.axline((0, 0), (57.6, 52.03))
ax.axline((0, 0), (69.81, 20.08))

#draw quadrants/ mean BOR & BTR
ax.vlines(x=mean_BOR, ymin=0, ymax=np.max(BOR) + 20, color='b')
ax.hlines(y=mean_BTR, xmin=0, xmax=np.max(BTR) + 20, color='b')

ax.set_xlabel("BOR", color="C0")
ax.set_ylabel("BTR", color="C0")
ax.tick_params(axis='x', colors="C0")
ax.tick_params(axis='y', colors="C0")
ax.set_xlim(xmin=0, xmax=np.max(BTR) + 20)
ax.set_ylim(ymin=0, ymax=np.max(BOR) + 20)

ax2.xaxis.tick_top()
ax2.yaxis.tick_right()
ax2.set_xlabel('ALOS', color="C1") 
ax2.set_ylabel('ALOS', color="C1")       
ax2.xaxis.set_label_position('top') 
ax2.yaxis.set_label_position('right') 
ax2.tick_params(axis='x', colors="C1")
ax2.tick_params(axis='y', colors="C1")
ax2.axes.xaxis.set_ticks([])
ax2.axes.yaxis.set_ticks([])

plt.show()


需要帮忙吗?或者已经有任何图书馆用于此目的。谢谢。

你走对了方向。matplotlib.axes对象具有添加其他单轴的方法

例如:

import numpy as np
import matplotlib.pyplot as plt

#2016/2017
xmax, ymax = 100, 100
ALS = np.array([4.04, 12.68, 2])
BOR = [57.6, 69.81, 40]
BTR = [52.03, 20.08, 80]
annotations = [2016, 2017, 2018]
mean_BTR = np.mean(BTR)
mean_BOR = np.mean(BOR)

fig = plt.figure()
plot = fig.add_subplot()
plot.set_xlim(0, xmax)
plot.set_ylim(0, ymax)

# add lines
for x, y, label in zip(BOR, BTR, annotations):
    plot.axline((0, 0), (x, y))
    plot.scatter((0, x), (0, y))
    plot.annotate(label, (x - 10, y))
plot.vlines(x=mean_BOR, ymin=0, ymax=ymax, color='b')
plot.hlines(y=mean_BTR, xmin=0, xmax=xmax, color='b')

# add right axis ticks
right_axis = plot.twinx()
right_axis.set_ylim(0, ymax)
right_ticks = np.array([ymax * y / x for x, y in zip(BOR, BTR)])
right_axis.set_yticks(right_ticks[right_ticks <= ymax])
right_axis.set_yticklabels(ALS[right_ticks <= ymax])

# add top axis ticks
top_axis = plot.twiny()
top_axis.set_xlim(0, xmax)
top_ticks = np.array([xmax * x / y for x, y in zip(BOR, BTR)])
top_axis.set_xticks(top_ticks[top_ticks < xmax])
top_axis.set_xticklabels(ALS[top_ticks < xmax])

# add labels
plot.set_xlabel('BOR')
plot.set_ylabel('BTR', color='g')
right_axis.set_ylabel("ALOS")
top_axis.set_xlabel("ALOS")

plt.show()
将numpy导入为np
将matplotlib.pyplot作为plt导入
#2016/2017
xmax,ymax=100100
ALS=np.数组([4.04,12.68,2])
波尔=[57.6,69.81,40]
BTR=[52.03,20.08,80]
注释=[2016、2017、2018]
平均值=np.平均值(BTR)
平均值=np.平均值(BOR)
图=plt.图()
绘图=图添加_子绘图()
plot.set_xlim(0,xmax)
plot.set_ylim(0,ymax)
#添加行
对于x、y,zip标签(BOR、BTR、注释):
轴测线(0,0,x,y))
散点图((0,x)、(0,y))
绘图注释(标签,(x-10,y))
plot.vlines(x=mean_BOR,ymin=0,ymax=ymax,color='b'))
plot.hlines(y=mean_BTR,xmin=0,xmax=xmax,color='b')
#添加右轴记号
右_轴=plot.twinx()
右_轴。设置_ylim(0,ymax)
右刻度=np.数组([ymax*y/x代表x,y在zip中(BOR,BTR)])
右轴。设置右刻度(右刻度[右刻度