示例#1
0
 def __init__(self):
     self.X = np.linspace(0, 4 * np.pi, 200)
     self.pt = Plotter(1, 2, width=700, height=500, useAgg=True)
     self.pt.set_xlabel("X")
     self.pt.use_grid()
     self.pt.add_annotation(0, "First")
     self.pt.add_annotation(199, "Last")
示例#2
0
 def __init__(self):
     """
     Constructs a Yampex Plotter object for a figure with two subplots.
     """
     self.pt = Plotter(2, width=self.width, height=self.height)
     self.pt.use_grid()
     self.pt.set_title("Exponentials plotted from {:.1f} to {:.1f}",
                       self.xMin, self.xMax)
     self.pt.set_xlabel("X")
     self.pt.set_ylabel("a*exp(-b*X)")
示例#3
0
 def __init__(self):
     """
     Constructs a Yampex Plotter object for a figure with two subplots.
     """
     self.mList = []
     # Small MOSFET in an IC
     self.mList.append(MOSFET(2.5e-9, 5e17))
     # High-current Power MOSFET
     self.mList.append(MOSFET(4e-9, 2.7e19))
     # Plotter
     self.N_sp = len(self.mList)
     self.pt = Plotter(self.N_sp, width=self.width, height=self.height)
     self.pt.use_grid()
     self.pt.set_xlabel("Vgst")
     self.pt.set_ylabel("Vdsp")
     self.pt.add_legend("Vgst/n")
     self.pt.add_legend("(Vgst-f(x))/n")
     self.pt.use_labels()
示例#4
0
class CurvePlotter(object):
    """
    I do the plotting.
    """
    width = 1400
    height = 1200
    N = 200

    def __init__(self):
        """
        Constructs a Yampex Plotter object for a figure with one subplot.
        """
        self.pt = Plotter(1, width=self.width, height=self.height)
        self.pt.use_grid()

    def eta(self, Vds, smooth=False):
        if smooth:
            eta = 0.05 * np.log(1 + np.exp(20 * (1 - Vds)))
        else:
            eta = np.clip(1 - Vds, 0, None)
        return eta

    def Cdg(self, eta):
        """
        The function for Cdg::
        
            Cdg = W*L*Cdox*(4+28*eta+22*eta^2+6*eta^3)/(15*(1+eta)^3)

        """
        result = 4 + 28 * eta + 22 * eta**2 + 6 * eta**3
        return result / (15 * (1 + eta)**3)

    def plot(self):
        """
        Plots the curve for Cdg vs Vds, given Vds_prime = 1.
        """
        self.pt.set_ylabel("Cdg")
        with self.pt as sp:
            sp.set_title("Cdg vs Vds")
            sp.set_xlabel("Vds")
            Vds = np.linspace(0, 2, self.N)
            eta = self.eta(Vds, True)
            Cdg = self.Cdg(eta)
            ax = sp(Vds, eta, Cdg)
        self.pt.show()
示例#5
0
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS
# IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language
# governing permissions and limitations under the License.
"""
A log plot, with several plots in one subplot, all done in one
call to the subplotting tool in context.
"""

import numpy as np
from yampex import Plotter

# Construct a Plotter object for a 1000x800 pixel (100 DPI) figure
# with a single subplot.
pt = Plotter(1, width=10.0, height=8.0)
# The plots will be of different bases raised to powers.
X = np.linspace(0, 10, 100)
pt.set_title("Different Bases Raised to Power 0-10")
# The x label will say "Power" and the subplot will have a grid.
pt.set_xlabel("Power")
pt.use_grid()

# Make a subplotting context and work with the single subplot via the
# subplot tool sp. It's actually just a reference to pt, but set up
# for subplotting.
with pt as sp:
    # Compute the vectors all at once
    Y2 = np.power(2, X)
    Y3 = np.power(3, X)
    Y10 = np.power(10, X)
示例#6
0
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS
# IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language
# governing permissions and limitations under the License.
"""
A sine and cosine plot in each of two subplots, with a call to the
L{SpecialAx} object.
"""

import numpy as np
from yampex import Plotter

# Construct a Plotter object for a 700x500 pixel (100 DPI) figure with
# two subplots.
pt = Plotter(1, 2, width=7.0, height=5.0)
# The plots, one in each subplot, will be of a sine and cosine with
# 200 points from 0 to 4*pi.
funcNames = ('sin', 'cos')
X = np.linspace(0, 4 * np.pi, 200)
pt.set_title("Sine and Cosine")
# Each subplot will have an x-axis label of "X" and a grid.
pt.set_xlabel("X")
pt.use_grid()
# Each plot will have an annotation labeled "Last" at its last
# point. Note that we can use negative indices referenced to the last
# element, just as with Python sequences.
pt.add_annotation(-1, "Last")

# Make a subplotting context and work with the two subplots via the
# subplot tool sp. It's actually just a reference to pt, but set up
示例#7
0
文件: mosfet_n.py 项目: edsuom/yampex
 def __init__(self):
     """
     Constructs a Yampex Plotter object for a figure with two subplots.
     """
     self.pt = Plotter(2, width=self.width, height=self.height)
     self.pt.use_grid()
示例#8
0
文件: mosfet_n.py 项目: edsuom/yampex
class CurvePlotter(object):
    """
    I do the plotting.
    """
    width = 1400
    height = 1400
    N = 100

    gamma = [0.5, 1.0, 2.5]
    Vgs = [0.0, 10.0]

    def __init__(self):
        """
        Constructs a Yampex Plotter object for a figure with two subplots.
        """
        self.pt = Plotter(2, width=self.width, height=self.height)
        self.pt.use_grid()

    def n(self, gamma, Vgs, Tj=25):
        """
        The function for n:

        M{n = 1+gamma/(-gamma+2*sqrt(gamma^2/4 + Vgs + 1.10/300*(Tj+273.15)))}
        """
        T = Tj + 273.15
        n = gamma.copy()  # Otherwise we wind up modifying gamma
        n /= -gamma + 2 * np.sqrt(gamma**2 / 4 + Vgs + 1.1 / 300 * T)
        n += 1
        return n

    def subplot(self, sp, X, aVals, bVals, semilog=False):
        """
        Given the subplotting tool I{sp} and the supplied 1-D Numpy array
        of I{X} values, plots the curves for each combination of I{a}
        in I{aVals} and I{b} in I{bVals}.
        """
        Ys = []
        for a, b in zip(aVals, bVals):
            Ys.append(self.func(X, a, b))
            sp.add_legend("a={:.2f}, b={:.2f}", a, b)
        if semilog:
            sp.semilogy(X, *Ys)
        else:
            sp(X, *Ys)

    def plot(self):
        """
        Plots the curves for each combination of I{a} in I{aVals} and its
        corresponding I{b} in I{bVals}, from my I{xMin} to my I{xMax}
        and from zero to double my I{xMax}.
        """
        self.pt.set_ylabel("n")
        with self.pt as sp:
            sp.set_title("n vs gamma with stepped Vgs")
            sp.set_xlabel("gamma")
            ax = sp()
            gamma = np.linspace(self.gamma[0], self.gamma[1], self.N)
            for Vgs in np.linspace(self.Vgs[0], self.Vgs[1], 5):
                with sp.prevOpts():
                    sp.add_legend("Vgs: {:.1f}", Vgs)
                n = self.n(gamma, Vgs)
                ax.plot(gamma, n)
            sp.set_title("n vs Vgs with stepped gamma")
            sp.set_xlabel("Vgs")
            ax = sp()
            Vgs = np.linspace(self.Vgs[0], self.Vgs[1], self.N)
            for gamma in np.linspace(self.gamma[0], self.gamma[1], 5):
                with sp.prevOpts():
                    sp.add_legend("gamma: {:.1f}", gamma)
                n = self.n(gamma, Vgs)
                ax.plot(Vgs, n)
        self.pt.show()
示例#9
0
Illustrates the use of L{options.OptsBase.use_timex} and calls to a
subplot-context instance of L{plot.Plotter} with multiple y-axis
arguments. Also shows a couple of intelligently-positioned
annotations.
"""

import numpy as np
from yampex import Plotter

EQs = ("sin(10*t)*cos(10000*t)", "cos(10*t)*cos(10000*t)")

N = 6
t = np.linspace(0, 2E-6, 1000)
# This time, we specify the plot dimensions in pixels with a tuple
pt = Plotter(N, figSize=(1600, 1200))
pt.set_title("With {:d} time scales: {}, {}", N, *EQs)
pt.use_timex()
pt.use_grid()
for eq in EQs:
    pt.add_legend(eq)
with pt as sp:
    for mult in range(N):
        X = t * 10**mult
        Y1 = np.sin(10 * X) * np.sin(10000 * X)
        Y2 = np.cos(10 * X) * np.cos(10000 * X)
        sp.set_title("0 - {:.5g} seconds", X[-1])
        if mult < 5 and np.any(Y2 < 0):
            sp.add_annotation(0.0, "Zero Crossing", kVector=1, y=True)
        sp(X, Y1, Y2)
pt.show()
示例#10
0
Illustrates the use of L{options.OptsBase.use_timex} and calls to a
subplot-context instance of L{plot.Plotter} with multiple y-axis
arguments.

Also illustrates how simply a row can be made twice as high as the
others.
"""

import numpy as np
from yampex import Plotter

N_sp = 4
N_pts = 200
X = np.linspace(0, 4 * np.pi, N_pts)
pt = Plotter(1, 4, width=10, height=10, h2=0)
pt.set_title("Sin(X) with increasingly noisy versions")
pt.set_zeroLine()
with pt as sp:
    Y = None
    for mult in np.logspace(-1.5, +0.5, N_sp):
        if Y is None:
            sp.add_textBox("SW",
                           "This subplot is twice as high as the others.")
        Y = np.sin(X)
        Y_noisy = Y + mult * np.random.randn(N_pts)
        k = np.argmax(np.abs(Y - Y_noisy))
        sp.add_textBox("NE", "Worst: {:+.3g} vs. {:+.3g}", Y_noisy[k], Y[k])
        ax = sp(X, Y)
        ax.plot(X, Y_noisy, 'r.')
pt.show()
示例#11
0
class CurvePlotter(object):
    """
    I do the plotting.
    """
    N = 100
    width = 1400
    height = 1400

    Vgs = [0.0, 10.0]

    def __init__(self):
        """
        Constructs a Yampex Plotter object for a figure with two subplots.
        """
        self.mList = []
        # Small MOSFET in an IC
        self.mList.append(MOSFET(2.5e-9, 5e17))
        # High-current Power MOSFET
        self.mList.append(MOSFET(4e-9, 2.7e19))
        # Plotter
        self.N_sp = len(self.mList)
        self.pt = Plotter(self.N_sp, width=self.width, height=self.height)
        self.pt.use_grid()
        self.pt.set_xlabel("Vgst")
        self.pt.set_ylabel("Vdsp")
        self.pt.add_legend("Vgst/n")
        self.pt.add_legend("(Vgst-f(x))/n")
        self.pt.use_labels()

    def Vdsp_1(self, m, Vgs):
        Vgst = Vgs - m.VT
        return Vgst / m.n(Vgs)

    def Vdsp_2(self, m, Vgs, x=0.1):
        Vgst = Vgs - m.VT
        n = m.n(Vgs)
        Pt = m.Pt
        second = 2 * n * Pt * np.log((1 + np.exp(Vgst /
                                                 (2 * n * Pt)))**np.sqrt(x) -
                                     1)
        return (Vgst - second) / n

    def plot(self):
        """
        """
        with self.pt as sp:
            for m in self.mList:
                sp.set_title("Vdsp vs Vgst, computed both ways, for {}", m)
                Vgs = np.linspace(self.Vgs[0], self.Vgs[1], 100)
                #sp(Vgs, self.Vdsp_1(m, Vgs), self.Vdsp_2(m, Vgs))
                sp(Vgs, self.Vdsp_2(m, Vgs))
        self.pt.show()
示例#12
0
文件: legend.py 项目: edsuom/yampex

def vectors(N):
    """
    Returns a list with X and C{k*sin(k*X)} for I{k} from 1 to I{N},
    where X is a 1-D Numpy vector having 200 points from 0 to M{4*pi}.
    """
    X = np.linspace(0, 4 * np.pi, 200)
    return [X] + [k * np.sin(k * X) for k in range(1, N + 1)]


# The number of waveforms
N = 3
# Construct a Plotter object for a 800x500 pixel (specified directly
# in pixels) figure with a single subplot.
pt = Plotter(1, width=800, height=500)
# As with many methods of opts.OptsBase, you can specify the title
# with a string formatting prototype and its argument(s).
pt.set_title("Sine Waves with {:d} frequency & amplitude multipliers", N)
# The x label will say "X" and the subplot will have a grid.
pt.set_xlabel("X")
pt.use_grid()

# Make a subplotting context and work with the single subplot via the
# subplot tool sp. It's actually just a reference to pt, but set up
# for subplotting.
with pt as sp:
    # Add legends for the plots. Again, a string formatting prototype
    # and its argument are used for convenience.
    for mult in range(1, N + 1):
        sp.add_legend("x{:d}", mult)
示例#13
0
class SinCos(object):
    funcNames = ('sin', 'cos')
    filePath = "sc.png"

    def __init__(self):
        self.X = np.linspace(0, 4 * np.pi, 200)
        self.pt = Plotter(1, 2, width=700, height=500, useAgg=True)
        self.pt.set_xlabel("X")
        self.pt.use_grid()
        self.pt.add_annotation(0, "First")
        self.pt.add_annotation(199, "Last")

    def __call__(self, frequency):
        self.pt.set_title("Sin and Cosine: Frequency = {:.2f}x", frequency)
        with self.pt as p:
            for funcName in self.funcNames:
                Y = getattr(np, funcName)(frequency * self.X)
                p.set_ylabel("{}(X)".format(funcName))
                p(self.X, Y)
        with open(self.filePath, "wb") as fh:
            self.pt.show(fh=fh)
示例#14
0
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS
# IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language
# governing permissions and limitations under the License.
"""
A variation of L{sincos}, with two plots in one subplot and a call
to the L{SpecialAx} object.
"""

import numpy as np
from yampex import Plotter

# Construct a Plotter object for a 1000x700 pixel (100 DPI) figure
# with a single subplot.
pt = Plotter(1, width=10.0, height=7.0)
# The plots will be of a sine (solid line) and cosine (dashed line)
# with 200 points from 0 to 4*pi.
funcNames = ('sin', 'cos')
X = np.linspace(0, 4 * np.pi, 200)
pt.set_title("Sine and Cosine")
pt.add_line('-', ':')
# The x label will say "X" and the subplot will have a grid.
pt.set_xlabel("X")
pt.use_grid()

# Make a subplotting context and work with the single subplot via the
# subplot tool sp. It's actually just a reference to pt, but set up
# for subplotting.
with pt as sp:
    # Placeholder for the SpecialAx object.
示例#15
0
class CurvePlotter(object):
    """
    I do the plotting.
    """
    width = 1400
    height = 1200
    xMin, xMax = 5.0, 8.0
    N = 100

    def __init__(self):
        """
        Constructs a Yampex Plotter object for a figure with two subplots.
        """
        self.pt = Plotter(2, width=self.width, height=self.height)
        self.pt.use_grid()
        self.pt.set_title("Exponentials plotted from {:.1f} to {:.1f}",
                          self.xMin, self.xMax)
        self.pt.set_xlabel("X")
        self.pt.set_ylabel("a*exp(-b*X)")

    def func(self, X, a, b):
        """
        The exponential function M{a*exp(-b*X)}
        """
        return a * np.exp(-b * X)

    def leastDiff(self, Ys, logspace=False):
        """
        Returns the index of the vectors of I{Ys} where there is the least
        difference between their values.

        Set I{logspace} C{True} to have the difference calculated in
        logspace, for a semilog plot.
        """
        Z = np.row_stack(Ys)
        if logspace: Z = np.log(Z)
        V = np.var(Z, axis=0)
        return np.argmin(V)

    def subplot(self, sp, X, aVals, bVals, semilog=False):
        """
        Given the subplotting tool I{sp} and the supplied 1-D Numpy array
        of I{X} values, plots the curves for each combination of I{a}
        in I{aVals} and I{b} in I{bVals}.

        Returns the value of I{X} where there is the least difference
        between the curves.
        """
        Ys = []
        for a, b in zip(aVals, bVals):
            Ys.append(self.func(X, a, b))
            sp.add_legend("a={:.2f}, b={:.2f}", a, b)
        k = self.leastDiff(Ys, semilog)
        sp.add_annotation(k, X[k])
        if semilog:
            sp.semilogy(X, *Ys)
        else:
            sp(X, *Ys)

    def plot(self, aVals, bVals):
        """
        Plots the curves for each combination of I{a} in I{aVals} and its
        corresponding I{b} in I{bVals}, from my I{xMin} to my I{xMax}
        and from zero to double my I{xMax}.
        """
        with self.pt as sp:
            # Top subplot: The range of interest
            X = np.linspace(self.xMin, self.xMax, self.N)
            self.subplot(sp, X, aVals, bVals)
            # Bottom subplot: Positive X surrounding the range of
            # interest
            X = np.linspace(0, 2 * self.xMax, self.N)
            sp.add_axvline(self.xMin)
            sp.add_axvline(self.xMax)
            self.subplot(sp, X, aVals, bVals, semilog=True)
        self.pt.show()