def main():
    x, y, z = [0], [0], [f(0, 0)]
    h, i = 0.1, 0
    while len(z) == 1 or abs(z[-2] - z[-1]) >= 0.0001:
        xi = x[-1] + (f(x[-1] + h, y[-1]) - z[-1]) / h
        yi = y[-1] + (f(x[-1], y[-1] + h) - z[-1]) / h
        x, y, z = x + [xi], y + [yi], z + [f(xi, yi)]
        if z[-2] >= z[-1]:
            h *= 0.5
        i += 1
    figure = make_subplots(
        cols=3,
        specs=[[{'type': 'xy'}, {'type': 'scene'}, {'type': 'scene'}]]
    )
    xg, yg = meshgrid(linspace(-2, 2, 100), linspace(-0.2, 1, 100))
    figure.add_trace(Scatter(x=x, y=y, name=''), row=1, col=1)
    figure.add_trace(Surface(x=xg, y=yg, z=f(xg, yg)), row=1, col=2)
    figure.add_trace(Scatter3d(x=x, y=y, z=z, name=''), row=1, col=2)
    xg, yg = meshgrid(linspace(-5, 5, 200), linspace(-5, 5, 200))
    figure.add_trace(Surface(x=xg, y=yg, z=f(xg, yg)), row=1, col=3)
    figure.add_trace(Scatter3d(x=x, y=y, z=z, name=''), row=1, col=3)
    figure.update_layout(
        title=f'x = {x[-1]:.4f}, y = {y[-1]:.4f}, z = {z[-1]:.4f}, h = {h}, i = {i}',
        showlegend=False
    )
    figure.show()
Example #2
0
 def surface(self, ax, X, Y, Z, color=None, label=None, **kwargs):
     return Surface(x=X,
                    y=Y,
                    z=Z,
                    name=label,
                    showlegend=label is not None,
                    **kwargs)
Example #3
0
def make_plot(args):
    """This function will generate a 3D surface plot."""
    raw_data = pd.read_csv(args.outprefix+'_matrix.tsv', sep="\t", dtype=float,
                           names=['length_pseudo', 'shared_hits', 'vals'], header=0)
    matrix = raw_data.pivot(index='length_pseudo', columns='shared_hits', values='vals')

    with common.suppress_output_to_console():
        data = [Surface(x=matrix.columns,
                        y=matrix.index,
                        z=matrix.values,
                        hovertemplate='length_pseudo: %{y}<br>'
                                      'shared_hits: %{x}<br>'
                                      'pseudogene calls: %{z}',
                        hoverlabel=dict(namelength=-1))]

        layout = Layout(
            scene=dict(
                xaxis=dict(title='shared_hits',
                           autorange=True),
                yaxis=dict(title='length_pseudo',
                           autorange=True),
                zaxis=dict(title='pseudogene calls',
                           autorange=True)
            )
        )

        fig = Figure(data=data, layout=layout)
        plot(fig, filename=args.outprefix+".html", auto_open=False)

    common.print_with_time("Figure plotted: %s.html" % args.outprefix)
Example #4
0
def _plot_sphere(radius, color, name, center=[0, 0, 0] * u.km):
    xx, yy, zz = _generate_sphere(radius, center)
    sphere = Surface(
        x=xx.to(u.km).value, y=yy.to(u.km).value, z=zz.to(u.km).value,
        name=name,
        colorscale=[[0, color], [1, color]],
        cauto=False, cmin=1, cmax=1, showscale=False,  # Boilerplate
    )
    return sphere
Example #5
0
    def _plot_sphere(self, radius, color, name, center=[0, 0, 0] * u.km):
        xx, yy, zz = generate_sphere(radius, center)
        sphere = Surface(
            x=xx.to(u.km).value,
            y=yy.to(u.km).value,
            z=zz.to(u.km).value,
            name=name,
            colorscale=[[0, color], [1, color]],
            cauto=False,
            cmin=1,
            cmax=1,
            showscale=False,
        )
        self._figure.add_trace(sphere)

        return sphere
Example #6
0
    def getGraphResult(self):
        _representSpeed = self.dfPacmod.query("remove==0").groupby(
            "groupBrake").mean()["speed"].values
        _representBrake = self.dfPacmod.query("remove==0").groupby(
            "groupBrake").mean()["brake"].values
        _representAcceleration = self.dfPacmod.query("remove==0").groupby(
            "groupBrake").mean()["accFiltered"].values

        _surface = Surface(x=self.brakeResult,
                           y=self.speedResult,
                           z=self.predictedAcceleration *
                           (self._accMaxNum - self._accMinNum) +
                           self._accMinNum,
                           colorscale='YlGnBu',
                           name="predictSurface")

        _scatterRepresent = Scatter3d(x=_representBrake,
                                      y=_representSpeed,
                                      z=_representAcceleration,
                                      mode='markers',
                                      marker=dict(size=2, color="green"),
                                      name="Boss")

        _scatterRemove = Scatter3d(
            x=self.dfPacmod.query("remove==0").brake,
            y=self.dfPacmod.query("remove==0").speed,
            z=self.dfPacmod.query("remove==0").accFiltered,
            mode='markers',
            marker=dict(size=3, color="blue"),
            name="RemoveOutliers")

        layout = go.Layout(title="ThrottleModel",
                           scene=dict(xaxis=dict(title="CMD(Brake)",
                                                 range=[0, 0.7]),
                                      yaxis=dict(title="speed", range=[20, 0]),
                                      zaxis=dict(title="acceleration",
                                                 range=[-3, 0])))

        fig = go.Figure(data=[_surface, _scatterRepresent, _scatterRemove],
                        layout=layout)

        _figName = "brake.html"
        print("saveGraphFileName:" + self.resultDirectory + _figName)
        plotly.offline.plot(fig, filename=self.resultDirectory + _figName)
Example #7
0
def make_plot(args):
    """This function will generate a 3D surface plot."""
    raw_data = pd.read_csv(args.outprefix + '_matrix.tsv',
                           sep="\t",
                           dtype=float,
                           names=['length_pseudo', 'shared_hits', 'vals'],
                           header=0)
    matrix = raw_data.pivot(index='length_pseudo',
                            columns='shared_hits',
                            values='vals')

    data = [Surface(x=matrix.columns, y=matrix.index, z=matrix.values)]

    layout = Layout(
        scene=Scene(xaxis=dict(title='shared_hits', autorange=True),
                    yaxis=dict(title='length_pseudo', autorange=True),
                    zaxis=dict(title=args.title, autorange=True)))

    fig = Figure(data=data, layout=layout)
    plot(fig, filename=args.outprefix + ".html", auto_open=False)
    print("%s\tFigure plotted: %s.html" % (current_time(), args.outprefix))
        width=5,
    ),
    mode="lines",
)

radius = molniya.attractor.R.to(u.km).value

uu, vv = np.mgrid[0:2 * np.pi:20j, 0:np.pi:10j]
xx = radius * np.cos(uu) * np.sin(vv)
yy = radius * np.sin(uu) * np.sin(vv)
zz = radius * np.cos(vv)

planet = Surface(x=xx,
                 y=yy,
                 z=zz,
                 cauto=False,
                 cmin=1,
                 cmax=1,
                 colorscale=[[0, '#204a87'], [1, '#204a87']],
                 showscale=False)

data = [trace, planet]

layout = dict(
    width=800,
    height=700,
    autosize=False,
    title='Orbit plot',
    scene=dict(
        xaxis=dict(gridcolor='rgb(255, 255, 255)',
                   zerolinecolor='rgb(255, 255, 255)',
                   showbackground=True,
Example #9
0
    file_formatter = logging.Formatter('%(asctime)s : %(message)s')
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)

    console_handler = logging.StreamHandler()
    console_handler.setFormatter(console_formatter)
    console_handler.setLevel(logging.INFO)
    logger.addHandler(console_handler)

    logger.info('started')

    x = y = np.arange(-5, 5, 0.1)
    yt = x[:, np.newaxis]
    z = np.cos(x * yt) + np.sin(x * yt) * 2

    f = Figure(data=[Surface(z=z, x=x, y=y, colorscale='Viridis')],
               layout=Layout(scene=Scene(
                   camera=Camera(up=dict(x=0, y=0, z=1),
                                 center=dict(x=0, y=0, z=0),
                                 eye=dict(x=1.25, y=1.25, z=1.25)))))

    plot(f, filename='out.html')

    # freq_slider = interactive(update_z, frequency=(1, 50, 0.1))
    # vb = VBox((f, freq_slider))
    # vb.layout.align_items = 'center'

    logger.info('done')

    finish_time = time()
    elapsed_hours, elapsed_remainder = divmod(finish_time - start_time, 3600)
Example #10
0
        y_data.append(float(row[1]))
        z_data.append(float(row[2]))

x_eq = float('1.55937729e-05')
y_eq = float('-2.27575413e-05')
z_eq = float('-1.45547286e-06')
intercept = float('-0.421052631579')

x = np.linspace(min(x_data), max(x_data), 100)
y = np.linspace(min(y_data), max(y_data), 100)
X, Y = np.meshgrid(x, y)

Z = (intercept - x_eq * X - y_eq * Y) / z_eq

print(Z)
surface = Surface(x=X, y=Y, z=Z)

z1 = [[intercept / z_eq, (intercept - x_eq) / z_eq],
      [(intercept - y_eq) / z_eq, (intercept - x_eq - y_eq) / z_eq]]

print(z1)

trace2 = Scatter3d(x=x_data,
                   y=y_data,
                   z=z_data,
                   mode='markers',
                   marker=dict(color='rgb(127, 127, 127)',
                               size=12,
                               symbol='circle',
                               line=dict(color='rgb(204, 204, 204)', width=1),
                               opacity=0.9))
Example #11
0
import plotly
from plotly.graph_objs import Layout, Surface

import pandas as pd

# Read data from a csv
z_data = pd.read_csv(
    'https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv'
)

data = [Surface(z=z_data.as_matrix())]
layout = Layout(title='Mt Bruno Elevation',
                autosize=False,
                width=500,
                height=500,
                margin=dict(l=65, r=50, b=65, t=90))

plotly.offline.plot({"data": data, "layout": layout})