LineGlyph¶
LineGlyph wraps Axes.plot, Axes.bar, and Axes.fill_between for line, bar, and band plots. y may be 1-D (one series) or 2-D (one series per column).
In [1]:
Copied!
import numpy as np
from cleopatra.glyphs.primitives.line_glyph import LineGlyph
x = np.linspace(0, 2 * np.pi, 100)
import numpy as np
from cleopatra.glyphs.primitives.line_glyph import LineGlyph
x = np.linspace(0, 2 * np.pi, 100)
1. Line plot (multiple series)¶
In [2]:
Copied!
y = np.column_stack([np.sin(x), np.cos(x)])
glyph = LineGlyph(x, y)
fig, ax, lines = glyph.line(label=['sin', 'cos'], title='Lines')
ax.legend()
y = np.column_stack([np.sin(x), np.cos(x)])
glyph = LineGlyph(x, y)
fig, ax, lines = glyph.line(label=['sin', 'cos'], title='Lines')
ax.legend()
Out[2]:
<matplotlib.legend.Legend at 0x7f977869b3b0>
2. Bar chart¶
In [3]:
Copied!
xb = np.arange(6)
glyph = LineGlyph(xb, np.array([3.0, 5.0, 2.0, 8.0, 4.0, 6.0]))
fig, ax, bars = glyph.bar(title='Bars')
xb = np.arange(6)
glyph = LineGlyph(xb, np.array([3.0, 5.0, 2.0, 8.0, 4.0, 6.0]))
fig, ax, bars = glyph.bar(title='Bars')
3. Band / envelope (fill_between)¶
In [4]:
Copied!
upper = np.sin(x) + 0.3
lower = np.sin(x) - 0.3
glyph = LineGlyph(x, upper)
fig, ax, band = glyph.fill_between(y2=lower, alpha=0.3, title='Band')
upper = np.sin(x) + 0.3
lower = np.sin(x) - 0.3
glyph = LineGlyph(x, upper)
fig, ax, band = glyph.fill_between(y2=lower, alpha=0.3, title='Band')