{ "cells": [ { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "xKU3RDZbNPAB" }, "source": [ "# **Ipychart - Plot Functions (Pandas Interface)**" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "vrIalhweNw0k" }, "source": [ "The second class of the ipychart API is the *ChartDataFrame* class. It allows you to create charts directly from your pandas dataframe.\n", "\n", "In this notebook you will find examples of how to create charts from your data loaded in a pandas dataframe with ipychart. All types of charts that can be created with the ChartDataFrame classs are implemented below. You can also find these examples in the official documentation of the package: https://nicohlr.gitlab.io/ipychart/" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "ElNf9ZbqlLey" }, "source": [ "## **Imports**" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "a5RKOM9LlKpb" }, "outputs": [], "source": [ "import pandas as pd\n", "import ipychart as ipc" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "s9oBg1ezpSOL" }, "source": [ "## **Load Data & create a ChartDataFrame instance**" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "VeHlQgMDp9d3" }, "outputs": [], "source": [ "titanic = pd.read_csv('titanic.csv')\n", "titanic['Age'] = titanic['Age'].fillna(titanic['Age'].median())\n", "titanic.head()" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "HKEUFIlAlt7y" }, "source": [ "## **Charts**" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "btYaVW3pl2HZ" }, "source": [ "### Count" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "fpFLZimWm_xJ" }, "outputs": [], "source": [ "ipc.countplot(data=titanic, x='Embarked', hue=\"Survived\")" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "sM4U8hmXl8oP" }, "source": [ "### Dist" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "V_qbHLg0nCUc" }, "outputs": [], "source": [ "ipc.distplot(data=titanic, x='Age')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "sL4fK8hgl8qv" }, "source": [ "### Line" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "xwx3ixYqnFHO" }, "outputs": [], "source": [ "datalabels_arguments = {'display': True, 'borderWidth': 1, 'anchor': 'end', \n", " 'align': 'end', 'borderRadius': 5, 'color': '#fff'}\n", "\n", "ipc.lineplot(data=titanic, x='Pclass', y='Age', hue='Sex', \n", " dataset_options={'fill': False, 'datalabels': datalabels_arguments}, \n", " colorscheme='office.Parallax6')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "-2-AJty9l8tQ" }, "source": [ " ### Bar " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "MWpWBaQXnLcg" }, "outputs": [], "source": [ "ipc.barplot(data=titanic, x='Pclass', y='Fare', hue='Sex', colorscheme='office.Parallax6')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "DQ9cxdUeq5EP" }, "source": [ "### Radar" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "U-udOfUGrbV6" }, "outputs": [], "source": [ "ipc.radarplot(data=titanic, x='Title', y='Fare', colorscheme='office.Yellow6')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "5Igo705drAOn" }, "source": [ "### Doughnut" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "OGE79vPbrb3u" }, "outputs": [], "source": [ "ipc.doughnutplot(data=titanic, x='Title', y='Fare', colorscheme='brewer.SetThree5')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "OnJW_Qo8l8vl" }, "source": [ "### Pie" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "KzypoXTbnP49" }, "outputs": [], "source": [ "ipc.pieplot(data=titanic, x='Title', y='Fare', colorscheme='brewer.SetThree5')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "0F34Vt0el8x_" }, "source": [ "### Polar Area" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "90j3GbEonTFy" }, "outputs": [], "source": [ "ipc.polarplot(data=titanic, x='Title', y='Fare', colorscheme='brewer.SetThree5')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "74p8gTWPmGT0" }, "source": [ "### Scatter" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "tlb757KAnWJs" }, "outputs": [], "source": [ "ipc.scatterplot(data=titanic, x='Age', y='Fare', hue='Survived', \n", " colorscheme='tableau.ColorBlind10')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "dKn_9JrxmGMQ" }, "source": [ "### Bubble" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "8MvSs8pYnZEp" }, "outputs": [], "source": [ "ipc.bubbleplot(data=titanic, x='Age', y='Fare', r='Pclass', hue='Survived', \n", " colorscheme='office.Headlines6')" ] } ], "metadata": { "colab": { "collapsed_sections": [], "name": "ChartDataFrame.ipynb", "provenance": [] }, "kernelspec": { "display_name": "ipychart-test", "language": "python", "name": "ipychart-test" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.0" } }, "nbformat": 4, "nbformat_minor": 4 }