# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Linechart Example

# +
from fractions import Fraction

import numpy as np

from pewdieplot.graph.linechart import LineChart
# -

# Create some data using sine, cosine and tangent curves.

x = np.arange(0, 2 * np.pi, 0.15)
sin_y = np.sin(x)
sin_points = np.dstack((x, sin_y))
cos_y = np.cos(x)
cos_points = np.dstack((x, cos_y))
tan_y = np.tan(x)
tan_points = np.dstack((x, tan_y))
all_points = np.concatenate((sin_points, cos_points, tan_points))

# Plot the curves defined above.
# Additionally use a PyPlot function call to draw an arrow indicating the local maximum of the sine curve.

# Build and show Line Chart.
(LineChart('Line Chart Example', size=(12, 7))
 .xlim(0, 2 * np.pi)
 .ylim(-4, 4)
 .xticks(np.arange(0, 2 * np.pi + 0.1, 0.5 * np.pi))
 .yticks(np.arange(-5, 5, 1))
 .xlabel_fn(lambda n: r'$%s\pi$' % Fraction(n / np.pi))
 .legends(['Sin', 'Cos', 'Tan'])
 .data(all_points)
 .pyplot('annotate', 'Sine Max', xy=(0.5 * np.pi, 1), xytext=(2.5, 2),
         arrowprops=dict(facecolor='black', shrink=0.05))
 ).show()
pass  # Supress object output in notebook.

StarcoderdataJupyterScriptsDedupFiltered