Following Last time, this time I will introduce the basic graph.
Graphs are basically drawn using classes that belong to the holoviews.element
module.
http://holoviews.org/Reference_Manual/holoviews.element.html
You can also check the list by looking at holoviews.elements_list
.
import holoviews as hv
print(hv.elements_list)
['Tabular', 'Curve', 'Annotation', 'Histogram', 'GridImage', 'Bounds', 'VectorField', 'Trisurface', 'HSV', 'Dataset', 'Area', 'Spikes', 'BoxWhisker', 'Spread', 'VLine', 'Spline', 'Chart', 'Surface', 'Element3D', 'Arrow', 'Polygons', 'Points', 'ErrorBars', 'QuadMesh', 'HeatMap', 'Ellipse', 'Box', 'Raster', 'Table', 'Text', 'Image', 'HLine', 'ItemTable', 'Element2D', 'Contours', 'Bars', 'Scatter', 'Element', 'Scatter3D', 'Path', 'BaseShape', 'RGB']
This time, I will introduce the basic graph holoviews.element.chart
.
Import the required modules and prepare sample data. (Please forgive me for not being a one-liner at this point)
import holoviews as hv
import numpy as np
hv.extension('bokeh')
np.random.seed(111)
x = np.linspace(-np.pi, np.pi, 100)
The backend is set in Bokeh, but it also works with matplotlib. Some graphs are not drawn with plotly.
hv.Curve((x, np.sin(x)))
hv.Area((x, np.sin(x)))
hv.Points(np.random.randn(100, 2))
Or
hv.Scatter(np.random.randn(100, 2))
The difference between Points
and Scatter
is being confirmed.
hv.Bars((list('abc'), range(1, 4)))
Since it does not calculate automatically, the frequency and the edge of the bin are calculated from numpy.
hv.Histogram(np.histogram(np.random.randn(1000)))
You can add a histogram by calling the hist
method from a graph such as a scatter plot. It's really easy.
hv.Points(np.random.randn(100, 2)).hist()
hv.BoxWhisker(np.random.randn(1000))
A line graph is added because it is not tasteful by itself.
hv.ErrorBars([(i, np.sin(i), np.random.rand() / 10)
for i in x]) * hv.Curve((x, np.sin(x)))
It is a graph that gives width to the original data. (I feel like I haven't explained it well, so I welcome Tsukkomi) It looks good to make a Bollinger band.
hv.Spread((x, np.sin(x), np.random.rand(100)))
hv.Spikes(np.random.randn(100))
You can also combine scatter plots as shown below.
p = hv.Points((np.random.randn(100, 2)))
p << hv.Spikes(p['y']) << hv.Spikes(p['x'])
hv.VectorField((range(10), range(10), np.random.rand(10), np.random.rand(10)))
TBD We will update it as soon as there is additional information.
If you have any content that you would like us to give priority to, please comment.
Recommended Posts