Plotting (legacy API)#
Note
This is a legacy API that’s kept for backwards compatibility.
Ensure you have matplotlib installed:
%pip install matplotlib --quiet
Note: you may need to restart the kernel to use updated packages.
%load_ext sql
Connect to an in-memory SQLite database.
%sql sqlite://
Connecting to 'sqlite://'
Line#
%%sql sqlite://
CREATE TABLE points (x, y);
INSERT INTO points VALUES (0, 0);
INSERT INTO points VALUES (1, 1.5);
INSERT INTO points VALUES (2, 3);
INSERT INTO points VALUES (3, 3);
1 rows affected.
1 rows affected.
1 rows affected.
1 rows affected.
points = %sql SELECT x, y FROM points
points.plot()
Running query in 'sqlite://'
/home/docs/checkouts/readthedocs.org/user_builds/jupysql/checkouts/938/src/sql/run/resultset.py:322: UserWarning: .plot() is deprecated and will be removed in a future version. For more help, find us at https://ploomber.io/community
warnings.warn(
<Axes: title={'center': 'y'}, xlabel='x', ylabel='y'>
Bar#
Note: sample data from the TIOBE index.
%%sql sqlite://
CREATE TABLE languages (name, rating, change);
INSERT INTO languages VALUES ('Python', 14.44, 2.48);
INSERT INTO languages VALUES ('C', 13.13, 1.50);
INSERT INTO languages VALUES ('Java', 11.59, 0.40);
INSERT INTO languages VALUES ('C++', 10.00, 1.98);
1 rows affected.
1 rows affected.
1 rows affected.
1 rows affected.
change = %sql SELECT name, change FROM languages
change.bar()
Running query in 'sqlite://'
/home/docs/checkouts/readthedocs.org/user_builds/jupysql/checkouts/938/src/sql/run/resultset.py:371: UserWarning: .bar() is deprecated and will be removed in a future version. Use %sqlplot bar instead. For more help, find us at https://ploomber.io/community
warnings.warn(
<Axes: xlabel='name', ylabel='change'>
Pie#
Data from Our World in Data.
%%sql sqlite://
CREATE TABLE energy_2021 (source, percentage);
INSERT INTO energy_2021 VALUES ('Oil', 31.26);
INSERT INTO energy_2021 VALUES ('Coal', 27.17);
INSERT INTO energy_2021 VALUES ('Gas', 24.66);
INSERT INTO energy_2021 VALUES ('Hydropower', 6.83);
INSERT INTO energy_2021 VALUES ('Nuclear', 4.3);
INSERT INTO energy_2021 VALUES ('Wind', 2.98);
INSERT INTO energy_2021 VALUES ('Solar', 1.65);
INSERT INTO energy_2021 VALUES ('Biofuels', 0.70);
INSERT INTO energy_2021 VALUES ('Other renewables', 0.47);
1 rows affected.
1 rows affected.
1 rows affected.
1 rows affected.
1 rows affected.
1 rows affected.
1 rows affected.
1 rows affected.
1 rows affected.
energy = %sql SELECT source, percentage FROM energy_2021
energy.pie()
Running query in 'sqlite://'
/home/docs/checkouts/readthedocs.org/user_builds/jupysql/checkouts/938/src/sql/run/resultset.py:285: UserWarning: .pie() is deprecated and will be removed in a future version. Use %sqlplot pie instead. For more help, find us at https://ploomber.io/community
warnings.warn(
<Axes: title={'center': 'percentage'}>