예제 #1
0
 def setup_axes(self):
     ax = SubplotZero(self.fig, 1, 1, 1)
     self.fig.add_subplot(ax)
     ax.set_xlabel('%s %s' % (self.ref_name, self.unit_string))
     ax.set_ylabel('%s %s' % (self.model_name, self.unit_string))
     ax.grid()
     self.ax = ax
예제 #2
0
파일: plotter.py 프로젝트: bcdev/opec-tools
 def setup_axes(self):
     ax = SubplotZero(self.fig, 1, 1, 1)
     self.fig.add_subplot(ax)
     ax.set_xlabel('%s %s' % (self.ref_name, self.unit_string))
     ax.set_ylabel('%s %s' % (self.model_name, self.unit_string))
     ax.grid()
     self.ax = ax
예제 #3
0
    def sketch(color, above, below, lw):
        fig = plt.figure(1)
        ax = SubplotZero(fig, 111)
        fig.add_subplot(ax)

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

        ac = patches.Arc(xy=(30, 70), width=30, height=20, angle=30, theta1=0, theta2=200, color=color,
                         linewidth=int(lw))
        ax.add_patch(ac)

        x_va = [42, 48, 63, 82]
        y_va = [40, 14, 44, 14]

        plt.plot(x_va, y_va, linewidth=int(lw), color=color)

        x_ha = [70, 80]
        y_ha = [70, 100]
        plt.plot(x_ha, y_ha, linewidth=int(lw), color=color)

        # hash line

        h1_x = [70, 82]
        h1_y = [70, 14]
        plt.plot(h1_x, h1_y, color=color, linewidth=int(lw), linestyle="dotted")

        # unsure hash line
        x_above = above[0]
        y_above = above[1]
        x_below = below[0]
        y_below = below[1]

        x1 = [79, x_above]
        y1 = [100, y_above]
        plt.plot(x1, y1, color=color, linewidth=int(lw), linestyle="dotted")

        x2 = [38, x_below]
        y2 = [44, y_below]
        plt.plot(x2, y2, color=color, linewidth=int(lw), linestyle="dotted")

        plt.xlim(-10, 130)
        plt.ylim(-10, 130)
        plt.show()
예제 #4
0
    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)
예제 #5
0
def cross_delete():
    fig = plt.figure(1)
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)

    for direction in ["top", "bottom", "left", "right"]:
        ax.axis[direction].set_visible(False)
    plt.plot([0, 20], [60, 60], linewidth=25, color="#fc4f30")
    plt.plot([20, 60], [60, 0], linewidth=25, color="#fc4f30", linestyle="dotted")
    plt.plot([60, 80], [0, 0], linewidth=25, color="#fc4f30")

    plt.plot([0, 20], [0, 0], linewidth=25, color="#008fd5")
    plt.plot([20, 60], [0, 60], linewidth=25, linestyle="dotted", color="#008fd5")
    plt.plot([60, 80], [60, 60], linewidth=25, color="#008fd5")
    plt.xlim(-10, 90)
    plt.ylim(-20, 80)
    plt.show()
예제 #6
0
    def __drawAxis__(self):
        """
        Draws the 2D cartesian axis
        """
        # A subplot with two additional axis, "xzero" and "yzero"
        # corresponding to the cartesian axis
        ax = SubplotZero(self.fig, 1, 1, 1)
        self.fig.add_subplot(ax)
        
        # make xzero axis (horizontal axis line through y=0) visible.
        for axis in ["xzero","yzero"]:
            ax.axis[axis].set_visible(True)
        # make the other axis (left, bottom, top, right) invisible
        for n in ["left", "right", "bottom", "top"]:
            ax.axis[n].set_visible(False)
            
        # Plot limits
        plt.xlim(self.xlim)
        plt.ylim(self.ylim)

        # Draw the arrows
        self.__arrow__(self.xlim[1], 0, 0.01, 0, 0.3, 0.2) # x-axis arrow
        self.__arrow__(0, self.ylim[1], 0, 0.01, 0.2, 0.3) # y-axis arrow
예제 #7
0
def cross():
    fig = plt.figure(1)
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)

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

    plt.plot([0, 50], [100, 50], color="#008fd5", linewidth=25)
    plt.plot([100, 50], [100, 50], color="#fc4f30", linewidth=25)
    plt.plot([0, 50], [0, 50], color="#6d904f", linewidth=25)
    plt.plot([100, 50], [0, 50], color="#e5ae37", linewidth=25)
    plt.scatter(50, 50, linewidths=70, color="k", zorder=10)
    plt.scatter(50, 50, linewidths=60, color="k", zorder=10)
    plt.scatter(50, 50, linewidths=50, color="k", zorder=10)
    plt.scatter(50, 50, linewidths=40, color="k", zorder=10)
    plt.scatter(50, 50, linewidths=30, color="k", zorder=10)
    plt.scatter(50, 50, linewidths=20, color="k", zorder=10)
    plt.scatter(50, 50, linewidths=10, color="k", zorder=10)

    plt.xlim(-10, 110)
    plt.ylim(-10, 110)
    plt.gca().set_aspect('equal', adjustable='box')
    plt.show()
예제 #8
0
However, according to the table above, it is found that, phenolphthalein changes colour within a pH high than 7 instead
    of equal to 7.
The phenolphthalein reacts with NaOH to change to pink. As the colour changes from pink to transparent, the colour
    would change before pH of seven. The whole line is decreasing, since it meets the end point first, then the
    equivalent point. (First change the colour, then neutralise)
"""

import matplotlib.pyplot as plt
from mpl_toolkits.axisartist import SubplotZero
import numpy as np
"""
a bug found! in SubplotZero, by saying xlabel and ylabel, xzeros and yzeros set the all axis label as xlabel
"""

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)

y = np.linspace(0, 20)
x = -(((y - 8)**5) / 1000) + 10
plt.plot(x, y)
plt.xlim(0, 25)
plt.ylim(0, 15)
예제 #9
0
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
from mpl_toolkits.axisartist import SubplotZero

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
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()
예제 #11
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)))))
예제 #12
0
"""
pH.py
sketch acid and base pH formula
# from mpl.toolkits.axisartist import Subplotzero
# ax.axis[direction].set_axisline_style("-|>")
# ax.axis[direction].set_visible(True||False)

"""

from matplotlib import pyplot as plt
from mpl_toolkits.axisartist import SubplotZero
import numpy as np

fig = plt.figure()
ax = SubplotZero(fig, 111)
ax.set_title("pH Formula")
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)

# log a(n) n > 0
x = np.linspace(0.01, 20, 2000)
y = np.log10(x)

plt.plot(x, -y, color="m", label="acid pH = -log{}{}[H{}O{}]".format("\N{SUBSCRIPT ONE}",
                                                                     "\N{SUBSCRIPT ZERO}",
예제 #13
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()
예제 #14
0
            success_count += 1

    i = loss_rates.index(int(loss_rate))

    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)
예제 #15
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)