Ejemplo n.º 1
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

import ltLaTeXpyplot as lt

# Create figure
fig = lt.ltFigure(name='fig', tight_layout=True)

# Define what to plot
t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
s2 = np.sin(2 * np.pi * t)

# Define graphs
fig.addgraph('graph1', x_label='time (s)', y_label='exp')
fig.addtwingraph('graph2', 'graph1', y_label='sin', axis='x')

# Insert object in plots
exp = lt.ltPlotFct(t, s1, color='b')
sin = lt.ltPlotPts(t, s2, color='r', marker='.')

# Add fit line
sin.plot(fig, 'graph2')
exp.plot(fig, 'graph1')

ax1 = fig.graphs['graph1'].graph
ax1.set_ylabel(fig.graphs['graph1'].y_label, color='b')
ax1.tick_params('y', colors='b', which='major')
ax1.tick_params('y', colors='b', which='minor')
                np.pi / steps)

print('  Creating orbitals: scatter plots...')

ntot = len(data.orbitals)
ncur = 0

size = 2000

for key in data.orbitals:
    cmap = 'coolwarm'
    if key in ['1s', 's', '00']:
        cmap += '_r'
    ncur += 1

    fig = lt.ltFigure(name='orbitale-' + key, height_width_ratio=1)
    max_range = data.r_on_a0_max["3x"] * data.a0
    fig.addgraph('graph1',
                 projection='3d',
                 x_ticks=False,
                 y_ticks=False,
                 z_ticks=False,
                 x_min=-max_range,
                 x_max=max_range,
                 y_min=-max_range,
                 y_max=max_range,
                 z_min=-max_range,
                 z_max=max_range)

    n = int(key[0])
    l = data.orbital_to_L[key[1]]
Ejemplo n.º 3
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Example taken from
# https://www.physique-experimentale.com/python/ajustement_de_courbe.py

import numpy as np

import ltLaTeXpyplot as lt

# Create figure
fig = lt.ltFigure(name='fig')

# Define what to plot
# data
x = np.array([1.0, 2.1, 3.1, 3.9])
y = np.array([2.1, 3.9, 6.1, 7.8])
# uncertainties (1 sigma)
ux = np.array([0.2, 0.3, 0.2, 0.2])
uy = np.array([0.3, 0.3, 0.2, 0.3])

reg = lt.ltPlotRegLin(x,
                      y,
                      ux,
                      uy,
                      info_placement='lower right',
                      label='Data',
                      label_reg='Regression')

# Définir le graphique
fig.addgraph('graph1',
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

import ltLaTeXpyplot as lt

# Create figure
fig = lt.ltFigure(name='fig', height_width_ratio=.725, width_frac=120.59/112.05)

# Define what to plot
price_data = np.load('goog.npz')['price_data'].view(np.recarray)
price_data = price_data[-250:]  # get the most recent 250 trading days

delta1 = np.diff(price_data.adj_close) / price_data.adj_close[:-1]

# Marker size in units of points^2
volume = (15 * price_data.volume[:-2] / price_data.volume[0])**2
close = 0.003 * price_data.close[:-2] / 0.003 * price_data.open[:-2]
    
# Define graphs
fig.addgraph('graph1', x_label='$\Delta_i$', y_label='$\Delta_{i+1}$', title='Volume and percent change', show_grid=True)

# Insert object in plots
fig.addplot(lt.ltPlotPts(delta1[:-1], delta1[1:], surface=volume, color=close, marker='o', alpha=0.5, cmap=None), 'graph1')

# Save figure
fig.save(format='pdf')
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

import ltLaTeXpyplot as lt

# Create figure
fig = lt.ltFigure(name='fig', tight_layout=True, height_width_ratio=.725)

# Define what to plot
# make these smaller to increase the resolution
dx = 0.05
dy = dx

# generate 2 2d grids for the x & y bounds
x = np.arange(1, 5, dx)
y = np.arange(1, 5, dy)


def z_fct(x, y):
    return np.sin(x)**10 + np.cos(10 + y * x) * np.cos(x)


# Define graphs
fig.addgraph('graph1',
             show_cmap_legend=True,
             position=211,
             title='Scalar field plot')
fig.addgraph('graph2',
             show_cmap_legend=True,
Ejemplo n.º 6
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

import ltLaTeXpyplot as lt

# Create figure
fig = lt.ltFigure(name='fig', height_width_ratio=1)

# Define what to plot


def get_demo_image():
    import numpy as np
    z = np.load('bivariate_normal.npy')
    # z is a numpy array of 15x15
    return z, (-3, 4, -4, 3)


# make data
Z, extent = get_demo_image()
Z2 = np.zeros([150, 150], dtype="d")
ny, nx = Z.shape
Z2[30:30 + ny, 30:30 + nx] = Z

xs = np.linspace(extent[0], extent[1], Z2.shape[0])
ys = np.linspace(extent[2], extent[3], Z2.shape[1])
zs = Z2

field = lt.ltPlotScalField(xs, ys, z_fct=zs, cmap='viridis')
Ejemplo n.º 7
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

import ltLaTeXpyplot as lt

# Create figure
fig = lt.ltFigure(name='EpH-fig')

# Define what to plot
C_tr = 0.01

EpHplt = lt.ltPlotEpH('Fe', C_tr)  # uses the EpH data of this package

# Define graphs
fig.addgraph('graph1',
             x_label='pH',
             y_label='$E$ ($\\SI{}{V}$)',
             show_legend=True,
             legend_on_side=False)

# Insert objects in graphs
fig.addplot(EpHplt, 'graph1')

# Save figure
fig.save(format='pdf')
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

import ltLaTeXpyplot as lt

# Create figure
fig = lt.ltFigure(name='fig', page_width_cm=26, width_frac=.6, height_width_ratio=1)

# Define what to plot
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
def z(x, y):
    return np.sin(np.sqrt(x**2+y**2))

surf = lt.ltPlotSurf(X, Y, z_fct=z, cmap='coolwarm', alpha=1, use_cmap=True, norm_xyz=False)
    
# Define graphs
fig.addgraph('graph1', show_cmap_legend=True, projection='3d')

# Insert objects in graphs
fig.addplot(surf, 'graph1')

# Save figure
fig.save(format='pdf')

################################################################################

# Create figure
fig2 = lt.ltFigure(name='fig2', height_width_ratio=.5, tight_layout=True)
theta = np.arange(0, np.pi * (1 + 1. / steps), np.pi / steps)
phi = np.arange(-np.pi * (1 + 1. / steps), np.pi * (1 + 1. / steps),
                np.pi / steps)

print('  Creating orbitals: Ylm real representations...')

ntot = 1  # len(data.Y_fcts_R)
ncur = 0
for key, Ylm in data.Y_fcts_R.items():
    if key != 'dz2':
        continue
    cmap = 'coolwarm'
    if key in ['s', '00']:
        cmap += '_r'
    ncur += 1
    fig = lt.ltFigure(name='orbitale-' + key, height_width_ratio=1)

    def R_fct(theta, phi):
        return (np.absolute(Ylm(theta, phi)))**2

    def C_fct(theta, phi):
        return (2 * np.sign(np.real(Ylm(theta, phi))) +
                np.sign(np.imag(Ylm(theta, phi)))) + 0 * theta

    max_range = 3 / 8
    fig.addgraph('graph1',
                 projection='3d',
                 x_ticks=False,
                 y_ticks=False,
                 z_ticks=False,
                 x_min=-max_range,
Ejemplo n.º 10
0
 def create(self, element, C_tr):
     fig = lt.ltFigure(name='test')
     fig.addgraph('graph1', x_label='pH', y_label='$E$ ($\\SI{}{V}$)')
     EpHplt = lt.ltPlotEpH(element, C_tr, pH_min=5, pH_max=6)
     fig.addplot(EpHplt, 'graph1')
     return EpHplt, fig.graphs['graph1']
Ejemplo n.º 11
0
# -*- coding: utf-8 -*-

import numpy as np

import ltLaTeXpyplot as lt
import ltLaTeXpyplot.data.orbitals.orbitals_data as data  # uses the orbital data of this package

r_on_a0 = np.arange(0, data.r_on_a0_MAX, 0.1)

radius = r_on_a0 * data.a0

Rnl = data.Rnl

for n, l in [(3, 0), (2, 1)]:
    figs = {
        'R': lt.ltFigure(name='fig-R{}{}'.format(n, l), width_frac=.25),
        'R2': lt.ltFigure(name='fig-R{}{}_squared'.format(n, l),
                          width_frac=.25),
        'p': lt.ltFigure(name='fig-R{}{}_proba'.format(n, l), width_frac=.25),
    }
    x = r_on_a0
    ys = {
        'R': Rnl(radius, n, l),
        'R2': Rnl(radius, n, l)**2,
        'p': 4 * np.pi * (radius)**2 * Rnl(radius, n, l)**2,
    }
    for subkey, fig in figs.items():
        fig.addgraph('graph1',
                     x_min=0,
                     x_max=data.r_on_a0_max['{}x'.format(n)],
                     y_ticks=False,
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

import ltLaTeXpyplot as lt

# Create figure
fig1 = lt.ltFigure(name='fig1')
fig2 = lt.ltFigure(name='fig2')

# Define what to plot
time = np.linspace(0, 100, 100)
x = np.sin(time / 10)
y = np.cos(time / 10)
z = time / time.max()

fct1 = lt.ltPlotFct3d(x, y, z, label='F1', color='C3', norm_xyz=True)
fct2 = lt.ltPlotFct3d(x, y, z, label='F1', color='C3', norm_xyz=False)

# Define graphs
fig1.addgraph('graph1', projection='3d')
fig2.addgraph('graph1', projection='3d')

# Insert object in plots
fct1.plot(fig1, 'graph1')
fct2.plot(fig2, 'graph1')

# Save figure
fig1.save(format='pdf')
fig2.save(format='pdf')
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

import ltLaTeXpyplot as lt

# Create figure
fig = lt.ltFigure(name='RMN-fig')

# Define what to plot
# signals = [signal1, signal2, ...]
# signalX = [deltaX, integral, multiplet, Js(Hz)]
signals = [
    lt.ltNMRsignal(4.999, 3, [4], [6.40]),
    lt.ltNMRsignal(1.374, 9, [2], [5.85])
]

spectrum = lt.ltPlotNMR(delta_min=.5,
                        delta_max=6,
                        Freq_MHz=90,
                        show_integral=True)
for signal in signals:
    spectrum.addsignal(signal)

# Define graphs
fig.addgraph('graph1')

# Insert objects in graphs
fig.addplot(spectrum, 'graph1')