{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Control Global and Local Plotting Themes {#themes_example}\n\nPyVista allows you to set global and local plotting themes to easily set\ndefault plotting parameters.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import pyvista as pv\nfrom pyvista import examples"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Define a simple plotting routine for comparing the themes.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "mesh = examples.download_st_helens().warp_by_scalar()\n\n\ndef plot_example():\n    p = pv.Plotter()\n    p.add_mesh(mesh)\n    p.add_bounding_box()\n    p.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "PyVista\\'s default color theme is chosen to be generally easy on your\neyes and is best used when working long hours on your visualization\nproject. The grey background and warm colormaps are chosen to make sure\n3D renderings do not drastically change the brightness of your screen\nwhen working in dark environments.\n\nHere\\'s an example of our default plotting theme - this is what you\nwould see by default after running any of our examples locally.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pv.set_plot_theme('default')\nplot_example()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "PyVista also ships with a few plotting themes:\n\n-   `'ParaView'`: this is designed to mimic ParaView\\'s default plotting\n    theme.\n-   `'dark'`: this is designed to be night-mode friendly with dark\n    backgrounds and color schemes.\n-   `'document'`: this is built for use in document style plotting and\n    making publication quality figures.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Demo the `'ParaView'` theme.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pv.set_plot_theme(\"paraview\")\n\nplot_example()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Demo the `'dark'` theme.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pv.set_plot_theme(\"dark\")\n\nplot_example()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Demo the `'document'` theme. This theme is used on our online examples.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pv.set_plot_theme(\"document\")\n\nplot_example()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Note that you can also use color gradients for the background of the\nplotting window.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plotter = pv.Plotter()\nplotter.add_mesh(mesh)\nplotter.show_grid()\n# Here we set the gradient\nplotter.set_background(\"royalblue\", top=\"aliceblue\")\ncpos = plotter.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Modifying the Global Theme\n\nYou can control how meshes are displayed by setting individual\nparameters when plotting like `mesh.plot(show_edges=True)`, or by\nsetting a global theme. You can also control individual parameters how\nall meshes are displayed by default via `pyvista.global_theme`.\n\nHere, we print out the current global defaults for all `pyvista` meshes.\nThese values have been changed by the previous \\\"Document\\\" theme.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pv.global_theme"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "By default, edges are not shown on meshes unless explicitly specified\nwhen plotting a mesh via `show_edges=True`. You can change this default\nbehavior globally by changing the default parameter.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pv.global_theme.show_edges = True\ncpos = pv.Sphere().plot()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "You can reset pyvista to default behavior with `restore_defaults`. Note\nthat the figure\\'s color was reset to the default \\\"white\\\" color rather\nthan the \\'lightblue\\' color default with the document theme. Under the\nhood, each theme applied changes the global plot defaults stored within\n`pyvista.global_theme.`\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pv.global_theme.restore_defaults()\ncpos = pv.Sphere().plot()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Creating a Custom Theme and Applying it Globally\n\nYou can create a custom theme by modifying one of the existing themes\nand then loading it into the global plotting defaults.\n\nHere, we create a dark theme that plots meshes red by default while\nshowing edges.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from pyvista import themes\n\nmy_theme = themes.DarkTheme()\nmy_theme.color = 'red'\nmy_theme.lighting = False\nmy_theme.show_edges = True\nmy_theme.axes.box = True\n\npv.global_theme.load_theme(my_theme)\ncpos = pv.Sphere().plot()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Creating a Custom Theme and Applying it to a Single Plotter\n\nIn this example, we create a custom theme from the base \\\"default\\\"\ntheme and then apply it to a single plotter. Note that this does not\nchange the behavior of the global \\\"defaults\\\", which are still set to\nthe modified `DarkTheme`.\n\nThis approach carries the advantage that you can maintain several themes\nand apply them to one or more plotters.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from pyvista import themes\n\nmy_theme = themes.DocumentTheme()\nmy_theme.color = 'black'\nmy_theme.lighting = True\nmy_theme.show_edges = True\nmy_theme.edge_color = 'white'\nmy_theme.background = 'white'\n\ncpos = pv.Sphere().plot(theme=my_theme)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Alternatively, set the theme of an instance of `Plotter`.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pl = pv.Plotter(theme=my_theme)\n# pl.theme = my_theme  # alternatively use the setter\npl.add_mesh(pv.Cube())\ncpos = pl.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Reset to use the document theme\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pv.set_plot_theme(\"document\")"
      ]
    }
  ],
  "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.12.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}