Beispiel #1
0
from mpl_toolkits.axisartist import SubplotZero
import numpy as np
import matplotlib.pyplot as plt

def f(t,a):
	return (t*t-a*a)**2

fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)

for direction in ["xzero", "yzero"]:
	ax.axis[direction].set_axisline_style("->")
	ax.axis[direction].toggle(ticks=False)
	ax.axis[direction].toggle(ticklabels=False)
	ax.axis[direction].set_visible(True)

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

t= np.arange(-1.5, 1.502, 0.002)
#ax.plot(t, f(t,1.0), 'k')
ax.plot(t, t*t, 'k')
plt.show()
Beispiel #2
0
from mpl_toolkits.axisartist import SubplotZero
import numpy as np
import matplotlib.pyplot as plt
from math import sin, cos


def f(x):
    return 1 - 9 * (sin(x) - x * cos(x))**2 / (x**6)


fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)

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

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

ax.axis["yzero"].set_axis_direction("top")
ax.axis["xzero"].label.set_text(r'$k_Fr$')
ax.axis["yzero"].label.set_text(r'$C_{\sigma\sigma}/\rho_0^2$')
ax.set_xticks(range(-8, 9, 2))
ax.set_ylim(0, 1.1)
ax.set_yticks(np.arange(0.2, 1.1, 0.2))
t = np.concatenate([np.arange(-8, 0, 0.002), np.arange(0.002, 8.002, 0.002)])
ax.plot(t, np.array(list(map(f, t))), 'k')
plt.show()
print(max(np.array(list(map(f, t)))))
    success[i] = success_count
    failed_reassembly[i] = fail_count
    sender_aborted[i] = s_abort_count
    receiver_aborted[i] = r_abort_count

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])
Beispiel #4
0
file1 = open('Generated files/file1.txt', 'w')
file1.close()
for i in range(len(res2['x'])):
    file1 = open('Generated files/file1.txt', 'a')
    results2 = "%s %s %s %s %s\n" % (str(res2['x'][i]), str(res2['y_my_func'][i]), str(res2['y_built_in'][i]), str(res2['absolute_error'][i]), str(res2['accuracy']))
    file1.write(results2)
file1.close()


# creation of file 2 as CSV due to Wolfram is bad with txt  
res = pd.DataFrame({'x': x_arg,'y': y_myfunc})
res.to_csv('Generated files/file2.csv', header=None, index=False)


#building graph
fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)

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

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

ax.plot(res['x'], res['y'], 'g', label = 'my function')
ax.scatter(res2['x'], res2['y_built_in'],color='red', label = 'built-in function')
plt.legend(loc='lower right')
plt.show()
Beispiel #5
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)