Python: How To Plot Pabon Lasso Chart Using Matplotlib?
I'm trying to plot a Pabon-Lasso chart using python's matplotlib library. Pabon-Lasso is a healthcare services efficiency/performance plot. I only found the R code library for the
Solution 1:
You are on the right track. The matplotlib.axes object has twinning methods that adds additional single axes.
For example:
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()
Post a Comment for "Python: How To Plot Pabon Lasso Chart Using Matplotlib?"