Altair is a python graphing package by Jake VanderPlas. Let's give it a try.
In [1]:
import altair as alt
import pandas as pd
import numpy as np
In [30]:
x = np.arange(-10, 11, 1)
y = 2 * x + 3
In [31]:
y
Out[31]:
In [32]:
source = pd.DataFrame({
'x': x,
'y': y
})
In [33]:
source
Out[33]:
In [34]:
alt.Chart(source).mark_line(point=True, clip=True).encode(
alt.X('x',
scale=alt.Scale(domain=(-20, 20))
),
y='y'
)
Out[34]:
In [180]:
x = np.arange(-10, 11, 1)
y = x**2
In [181]:
source = pd.DataFrame({
'x': x,
'y': y
})
In [182]:
alt.Chart(source).mark_line(point=True).encode(
x=alt.X('x'),
y='y'
)
Out[182]:
In [67]:
x = np.arange(0, 26, 0.1)
y = np.sqrt(x)
In [68]:
source = pd.DataFrame({
'x': x,
'y': y
})
In [76]:
a = alt.Chart(source).mark_line(point=True).encode(
x=alt.X('x'),
y='y'
)
a.properties(height=500, width=700)
Out[76]:
In [ ]:
r = 10
i = 0.1
x1 = np.arange(-10, 10.1, i)
x2 = np.arange(10, -10.1, -i)
y1 = np.sqrt(r**2 - x1**2)
y2 = -np.sqrt(r**2 - x2**2)
x = np.concatenate((x1, x2))
y = np.concatenate((y1, y2))
In [128]:
source = pd.DataFrame({
'x': x,
'y': y
})
In [129]:
source
Out[129]:
In [130]:
a = alt.Chart(source).mark_line(point=True).encode(
alt.X('x',
scale=alt.Scale(domain=(-12, 12)),
sort=[False],
),
alt.Y('y',
scale=alt.Scale(domain=(-12, 12)),
),
)
a.properties(height=500, width=520)
Out[130]:
In [ ]: