2016-2017/3e/DS/DNBpro_blanc2/Eolienne_graph_stat/Create cat plot.ipynb

259 lines
23 KiB
Plaintext
Raw Normal View History

2017-06-16 06:49:23 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"plt.style.use(\"seaborn-notebook\")\n",
"import seaborn as sns\n",
"cm = sns.light_palette(\"green\", as_cmap=True)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"wspeed = pd.DataFrame(np.random.normal(7,7, 365)).abs()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>365.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>8.078493</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>5.286526</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>0.010161</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>4.003320</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>7.400571</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>11.234191</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>26.713693</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0\n",
"count 365.000000\n",
"mean 8.078493\n",
"std 5.286526\n",
"min 0.010161\n",
"25% 4.003320\n",
"50% 7.400571\n",
"75% 11.234191\n",
"max 26.713693"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wspeed.describe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sns.countplot()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def cate(ws):\n",
" if ws[0] < 5:\n",
" return \"Pas assez de vent\"\n",
" elif ws[0] < 10:\n",
" return \"Peu de vent\"\n",
" elif ws[0] < 15:\n",
" return \"Vent léger\"\n",
" elif ws[0] < 20:\n",
" return \"Bon vent\"\n",
" elif ws[0] < 25:\n",
" return \"Vent fort\"\n",
" else:\n",
" return \"Trop de vent\""
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"wspeed[\"cat\"] = wspeed.apply(cate, axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.axis.YTick at 0x7f17a6895908>,\n",
" <matplotlib.axis.YTick at 0x7f17a68f3b00>,\n",
" <matplotlib.axis.YTick at 0x7f17a690c710>,\n",
" <matplotlib.axis.YTick at 0x7f17a687a7b8>,\n",
" <matplotlib.axis.YTick at 0x7f17a6882128>,\n",
" <matplotlib.axis.YTick at 0x7f17a686e8d0>,\n",
" <matplotlib.axis.YTick at 0x7f17a6882b38>,\n",
" <matplotlib.axis.YTick at 0x7f17a6885630>,\n",
" <matplotlib.axis.YTick at 0x7f17a688e128>,\n",
" <matplotlib.axis.YTick at 0x7f17a688ebe0>,\n",
" <matplotlib.axis.YTick at 0x7f17a68946d8>,\n",
" <matplotlib.axis.YTick at 0x7f17a681a1d0>,\n",
" <matplotlib.axis.YTick at 0x7f17a681ac88>]"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/lafrite/.virtualenvs/enseignement/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans\n",
" (prop.get_family(), self.defaultFamily[fontext]))\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAfQAAAFKCAYAAADrFq2PAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XtUVOXeB/DvwEgqCYICHgw9Spq8KGJJOsu8oYBycfCu\nlQXVi4dKRczUNCyzsDLjZNmBQ0epTFPUwQQUQREy7+bd8og3tGA44yAIKgw87x8s5pUjOIjMDLP9\nftZyLWfP7Of58cye+c5+Zu89MiGEABEREVk0K3MXQERERA+PgU5ERCQBDHQiIiIJYKATERFJAAOd\niIhIAuTmLuBhFBWVmrsEIiIik3Jyalfvcu6hExERSQADnYiISAIY6ERERBLAQCciIpIABjoREZEE\nMNCJiIgkgIFOREQkAQx0IiIiCWCgExERSQADnYiISAIY6ERERBLAQCciIpIABjoREZEEMNCJiIgk\nwKJ/PpXIlFatWmHuEkzq9dejzV0CET0A7qETERFJAAOdiIhIAhjoREREEsBAJyIikgAGOhERkQQw\n0ImIiCSAgU5ERCQBRgv0BQsWQKFQIDg4WL/s448/xqhRoxASEoI33ngDJSUl+vvi4+Ph5+eHgIAA\n5ObmGqssIiIiSTLahWXGjRuHF198EfPmzdMvGzRoEObMmQO5XI5PP/0U8fHxmDt3Ls6fP4/U1FSk\npqaisLAQ4eHh2LFjB6ytrR+qhkfpQiC8CAgR0aPNaHvoPj4+sLe3r7Psueeeg1xe8xnC29sbBQUF\nAICsrCwEBQXBxsYGbm5u6Nq1K06cOGGs0oiIiCTHbJd+3bRpE0aPHg0AKCwsRN++ffX3ubi4oLCw\n0GAbDg5tIZc/3F68VDg5tTN3CSQx3KaILItZAv3rr7+GtbU1xowZ81DtaLXlzVSR5SsqKjV3CSQx\n3KaIWqaGPmybPNA3b96M7OxsrFmzBjKZDEDNHnnt9D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ICkpCQzVENERGT5eKU4IiIiCWCgExERSQADnYiISAIY6ERERBLAQCciIpIABjoREZEEGAz0\nQ4cOoaysDACwceNGxMTEID8/3+iFERERUeMZDPQlS5agbdu2+Pe//43Vq1fD1dUVCxcuNEVtRERE\n1EgGLywjl8shk8mQk5ODqVOnYtq0adi+fbspaiMTWbVqhblLMKnXX482dwlERM3O4B66TqfD8ePH\nsXPnTgwcOBAAUFVVZfTCiIiIqPEMBnpUVBRiYmLg7e2NHj164OLFi+jataspaiMiIqJGuu+Ue1VV\nFf7zn/8gJSVFv6xbt2748ssvjV4YERERNd5999Ctra3x448/mqoWIiIiaiKDU+4DBgzgQXBEREQt\nnMGj3Lds2YLVq1ejdevWaNOmDYQQkMlk2LdvX5M7XbNmDTZu3AiZTIaePXsiNjYWarUa0dHRKC4u\nhqenJz755BPY2Ng0uQ8iIqJHicFA37RpU7N2WFhYiG+//RZpaWlo3bo1Zs2ahdTUVOzZswdhYWEI\nCgpCTEwMkpOT8fzzzzdr30RERFJlcMq9c+fO9f57GFVVVbh9+zZ0Oh1u374NJycn7N+/HwEBAQCA\nsWPHIisr66H6ICIiepQY3EMfOHAgZDLZPcubOuXu4uKCV155BcOHD8djjz2GQYMGwdPTE3Z2dpDL\na8rp1KkTCgsLDbbl4NAWcrl1k+qQGienduYuwWJwrBqH40RkWR5oyv3OnTv46aef9MHbFDdu3EBW\nVhaysrLQrl07zJo1C7m5uU1qS6stb3IdUlNUVGruEiwGx6pxOE5ELVNDH7YfaMq9e/fumDVrFvbs\n2dPkQn755Rc88cQTcHR
"text/plain": [
"<matplotlib.figure.Figure at 0x7f17a72b9b00>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ax = sns.countplot(x=\"cat\", data=wspeed, color=\"grey\")\n",
"ax.set_xlabel(\"\")\n",
"ax.set_ylabel(\"Nombre de jours\")\n",
"ax.set_yticks(np.arange(0, 130, 10))"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/lafrite/.virtualenvs/enseignement/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans\n",
" (prop.get_family(), self.defaultFamily[fontext]))\n"
]
}
],
"source": [
"ax.figure.savefig(\"./fig/cat_vent.svg\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}