print(f"Success:\n{success}")
print(f"Failed reassembly:\n{failed_reassembly}")
print(f"Sender aborted:\n{sender_aborted}")
print(f"Receiver aborted:\n{receiver_aborted}")

fig = plt.figure()
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
ax.grid(True, ls='dotted')
x_axis = [l / 100 for l in loss_rates]
ax.plot(x_axis, [x / 100 for x in sender_aborted])
ax.plot(x_axis, [x / 100 for x in receiver_aborted])
ax.plot(x_axis, [x / 100 for x in failed_reassembly], color='r', linewidth=4)
ax.set_xlabel("Fragment loss rate")
ax.set_ylabel("Occurrences / Total experiments")
ax.set_xlim((0, 1))
ax.set_ylim((0, 1))
plt.legend(["Sender-Aborted", "Receiver-Aborted", "Failed reassembly"])
plt.show()
fig.savefig("failed_total.png")

fail_rate = [None] * len(loss_rates)
completion_rate = [None] * len(loss_rates)
for i in range(len(loss_rates)):
    try:
        fail_rate[i] = failed_reassembly[i] / (success[i] + failed_reassembly[i])
        completion_rate[i] = (success[i] + failed_reassembly[i]) / 100
    except ZeroDivisionError:
        fail_rate[i] = None

fig = plt.figure()
Exemple #2
0
x_data = []
y_data = []

fig = plt.figure()
ax = SubplotZero(fig, 111)
ax.set_title("Add HCl to NaOH Solution\npH of NaOH Solution")
fig.add_subplot(ax)

for direction in ["xzero", "yzero"]:
    ax.axis[direction].set_axisline_style("-|>")
    ax.axis[direction].set_visible(True)

for direction in ["top", "bottom", "left", "right"]:
    ax.axis[direction].set_visible(False)

ax.set_xlim(0, 25)
ax.set_ylim(0, 15)
plt.gca().set_aspect('equal')
plt.axhline(7, color="r")
plt.scatter(10, 7, marker="o", color="b")
plt.annotate(s="Equivalence Point (NaOH Solution Neutralised)", xy=(10.5, 7.5))
plt.annotate("Amount of HCl Adding", (9, .4))
plt.annotate("NaOH\nSolution\npH", (1, 12))

plt.fill_between((0, 25),
                 8.2,
                 10,
                 color="g",
                 alpha=0.2,
                 label="End Point \n(Phenolphthalein Changes Colour)")
Exemple #3
0
class OrthogonalCoord:
    ax: Axes

    def __init__(self, min_size=-2, max_size=8,show_grid=True):
        """
        初始化整个屏幕的范围。绘制笛卡尔坐标轴、刻度、网格
        :param min_size: 负值,x y坐标轴的最小值
        :param max_size: 正值,x y的最大值
        """
        # max_size = 8
        # min_size = -2
        # 本身就应该已经有一个plot了。这个plt可以通过调用figure,来构造一个新的图形。
        # fig可以通过add_subplot,为自己添加一个坐标系
        # 绘图是以坐标系为基础的。
        fig = plt.figure(figsize=(max_size - min_size, max_size - min_size), dpi=72)
        self.ax = SubplotZero(fig, 111)
        fig.add_subplot(self.ax)

        # xaxis又不是AxisArtist,那它是什么类型? Axes又和Axis不同,这是两个什么东西呢?
        # 显示刻度
        ticks = [i for i in range(min_size, max_size) if i != 0]
        self.ax.xaxis.set_ticks(ticks)
        self.ax.yaxis.set_ticks(ticks)
        # 锁定纵横比
        self.ax.set_aspect("equal")
        # 显示网格
        self.ax.grid(show_grid)
        self.ax.set_xlim(min_size, max_size)
        self.ax.set_ylim(min_size, max_size)

        for direction in ["xzero", "yzero"]:
            # adds arrows at the ends of each axis
            axis: AxisArtist = self.ax.axis[direction]
            axis.set_axisline_style("->")
            axis.set_visible(True)

        for direction in ["left", "right", "bottom", "top"]:
            # hides borders
            self.ax.axis[direction].set_visible(False)

    def draw_vector(self, point: array, with_components=False, color="black"):
        """
        在笛卡尔坐标系中绘制向量
        :param color:
        :param point:
        :param with_components: 是否绘制笛卡尔分量
        :return:
        """
        self.ax.plot([0, point[0]],
                     [0, point[1]], color=color, linewidth=2)
        if with_components:
            self.draw_components(point)

    def draw_components(self, point: []):
        """
        绘制一个向量的笛卡尔坐标分量
        从表示向量的点,分别向两个坐标轴绘制虚线
        """
        self.ax.plot([point[0], point[0]],
                     [point[1], 0], color="black", linestyle="dashed", linewidth=1)
        self.ax.plot([point[0], 0],
                     [point[1], point[1]], color="black", linestyle="dashed", linewidth=1)