{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = {'a': np.arange(50),\n", " 'c': np.random.randint(0, 50, 50),\n", " 'd': np.random.randn(50)}\n", "data['b'] = data['a'] + 10 * np.random.randn(50)\n", "data['d'] = np.abs(data['d']) * 100\n", "\n", "plt.scatter('a', 'b', c='c', s='d', data=data)\n", "plt.xlabel('entry a')\n", "plt.ylabel('entry b')\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create Figure and Subplots\n", "fig, (ax1, ax2) = plt.subplots(1,2, figsize=(10,4), sharey=True, dpi=120)\n", "\n", "# Plot\n", "ax1.plot([1,2,3,4,5], [1,2,3,4,10], 'go') # greendots\n", "ax2.plot([1,2,3,4,5], [2,3,4,5,11], 'b*') # bluestart\n", "\n", "# Title, X and Y labels, X and Y Lim\n", "ax1.set_title('Scatterplot Greendots'); ax2.set_title('Scatterplot Bluestars')\n", "ax1.set_xlabel('X'); ax2.set_xlabel('X') # x label\n", "ax1.set_ylabel('Y'); ax2.set_ylabel('Y') # y label\n", "ax1.set_xlim(0, 6) ; ax2.set_xlim(0, 6) # x axis limits\n", "ax1.set_ylim(0, 12); ax2.set_ylim(0, 12) # y axis limits\n", "\n", "# ax2.yaxis.set_ticks_position('none') \n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from matplotlib.ticker import FuncFormatter\n", "\n", "def rad_to_degrees(x, pos):\n", " 'converts radians to degrees'\n", " return round(x * 57.2985, 2)\n", "\n", "plt.figure(figsize=(12,7), dpi=100)\n", "X = np.linspace(0,2*np.pi,1000)\n", "plt.plot(X,np.sin(X))\n", "plt.plot(X,np.cos(X))\n", "\n", "# 1. Adjust x axis Ticks\n", "plt.xticks(ticks=np.arange(0, 440/57.2985, 90/57.2985), fontsize=12, rotation=30, ha='center', va='top') # 1 radian = 57.2985 degrees\n", "\n", "# 2. Tick Parameters\n", "plt.tick_params(axis='both',bottom=True, top=True, left=True, right=True, direction='in', which='major', grid_color='blue')\n", "\n", "# 3. Format tick labels to convert radians to degrees\n", "formatter = FuncFormatter(rad_to_degrees)\n", "plt.gca().xaxis.set_major_formatter(formatter)\n", "\n", "plt.grid(linestyle='--', linewidth=0.5, alpha=0.15)\n", "plt.title('Sine and Cosine Waves\\n(Notice the ticks are on all 4 sides pointing inwards, radians converted to degrees in x axis)', fontsize=14)\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import seaborn as sns\n", "sns.set(style=\"whitegrid\", palette=\"pastel\", color_codes=True)\n", "\n", "# Load the example tips dataset\n", "tips = sns.load_dataset(\"tips\")\n", "\n", "# Draw a nested violinplot and split the violins for easier comparison\n", "sns.violinplot(x=\"day\", y=\"total_bill\", hue=\"smoker\",\n", " split=True, inner=\"quart\",\n", " palette={\"Yes\": \"y\", \"No\": \"b\"},\n", " data=tips)\n", "sns.despine(left=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from mpl_toolkits.mplot3d import Axes3D\n", "import matplotlib.pyplot as plt\n", "\n", "%matplotlib notebook\n", "\n", "fig = plt.figure()\n", "ax = fig.add_subplot(111, projection='3d')\n", "\n", "x =[1,2,3,4,5,6,7,8,9,10]\n", "y =[5,6,2,3,13,4,1,2,4,8]\n", "z =[2,3,3,3,5,7,9,11,9,10]\n", "\n", "ax.scatter(x, y, z, c='r', marker='o')\n", "\n", "ax.set_xlabel('X Label')\n", "ax.set_ylabel('Y Label')\n", "ax.set_zlabel('Z Label')\n", "\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.7" } }, "nbformat": 4, "nbformat_minor": 4 }