[PYTHON] One-liner basic graph of HoloViews

Following Last time, this time I will introduce the basic graph.

Graph type

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.

Advance preparation

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.

Line graph

hv.Curve((x, np.sin(x)))

curve.png

Area graph

hv.Area((x, np.sin(x)))

area.png

Scatter plot

hv.Points(np.random.randn(100, 2))

Or

hv.Scatter(np.random.randn(100, 2))

points.png

The difference between Points and Scatter is being confirmed.

bar graph

hv.Bars((list('abc'), range(1, 4)))

bars.png

histogram

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)))

histogram.png

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()

image.png

Box plot

hv.BoxWhisker(np.random.randn(1000))

boxwhisker.png

Error bar

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)))

errorbars.png

Spread

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)))

spread.png

spectrum

hv.Spikes(np.random.randn(100))

spikes.png

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'])

image.png

Vector field

hv.VectorField((range(10), range(10), np.random.rand(10), np.random.rand(10)))

vectorfield.png

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

One-liner basic graph of HoloViews
Basic operation of pandas
Basic usage of flask-classy
Basic usage of Jinja2
Basic operation of Pandas
Basic usage of SQLAlchemy
Basic processing of librosa
Super basic usage of pytest
Basic usage of PySimple GUI
Basic flow of anomaly detection
XPath Basics (1) -Basic Concept of XPath
Basic usage of Pandas Summary
Connected components of the graph
Basic usage of Python f-string
Interactive plot of 3D graph
Basic knowledge of Linux and basic commands
Summary of basic knowledge of PyPy Part 1
A collection of one-liner web servers
One-liner processing of quagmire memory (CSV)
About the basic type of Go
Basic grammar of Python3 system (dictionary)
Basic study of OpenCV with Python