
verticapy.jupyter.extensions.chart_magic.chart_magic¶
- verticapy.jupyter.extensions.chart_magic.chart_magic(line: str, cell: str | None = None, local_ns: dict | None = None) Highstock | Highchart ¶
Draws responsive charts using the Matplotlib, Plotly, or Highcharts library.
Different cutomization parameters are available for Plotly, Highcharts, and Matplotlib. For a comprehensive list of customization features, please consult the documentation for the respective plotting libraries: plotly, matplotlib and highcharts.
Parameters¶
- -c / –commandstr, optional
SQL Command to execute.
- -f / –filestr, optional
Input File. You can use this option if you want to execute the input file.
- -k / –kindstr, optional
Chart Type, one of the following:
- area:
Area Chart.
- area_range:
Area Range Chart.
- area_ts:
Area Chart with Time Series Design.
- bar:
Bar Chart.
- biserial:
Biserial Point Matrix (Correlation between binary variables and numerical)
- boxplot:
Box Plot.
- bubble:
Bubble Plot.
- candlestick:
Candlestick and Volumes (Time Series Special Plot).
- cramer:
Cramer’s V Matrix (Correlation between categories).
- donut:
Donut Chart.
- donut3d:
3D Donut Chart.
- heatmap:
Heatmap.
- hist:
Histogram.
- kendall:
Kendall Correlation Matrix.
Warning
This method uses a CROSS JOIN during computation and is therefore computationally expensive at O(n * n), where n is the total count of the
vDataFrame
.
- line:
Line Plot.
- negative_bar:
Multi-Bar Chart for binary classes.
- pearson:
Pearson Correlation Matrix.
- pie:
Pie Chart.
- pie_half:
Half Pie Chart.
- pie3d:
3D Pie Chart.
- scatter:
Scatter Plot.
- spider:
Spider Chart.
- spline:
Spline Plot.
- stacked_bar:
Stacker Bar Chart.
- stacked_hist:
Stacked Histogram.
- spearman:
Spearman Correlation Matrix.
- -o / –outputstr, optional
Output File. You can use this option if you want to export the result of the query to the HTML format.
Returns¶
Chart Object
Examples¶
The following examples demonstrate:
Setting up the environment
Drawing graphics
Exporting to HTML
Using variables
Using SQL files
Hint
To see more examples, please refer to the ref:chart_gallery.guide.
Setting up the environment¶
If you don’t already have one, create a new connection:
import verticapy as vp # Save a new connection vp.new_connection( { "host": "10.211.55.14", "port": "5433", "database": "testdb", "password": "XxX", "user": "dbadmin", }, name = "VerticaDSN", )
Otherwise, to use an existing connection:
vp.connect("VerticaDSN")
Load the chart extension:
Run the following to load some sample datasets. Once loaded, these datasets are stored in the ‘public’ schema. You can change the target schema with the ‘schema’ parameter:
from verticapy.datasets import load_titanic, load_amazon, load_iris titanic = load_titanic() amazon = load_amazon() iris = load_iris()
Use the
set_option()
function to set your desired plotting library:vp.set_option("plotting_lib","plotly")
Drawing graphics¶
The following examples draw various responsive charts from SQL queries.
Pie Chart¶
%chart -k pie -c "SELECT pclass, AVG(age) AS av_avg FROM titanic GROUP BY 1;"
Line Plot¶
%%chart -k line SELECT date, AVG(number) AS number FROM amazon GROUP BY 1;