Using radio buttons to choose properties of your plot.
Radio buttons let you choose between multiple options in a visualization.
In this case, the buttons let the user choose one of the three different sine
waves to be shown in the plot.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import RadioButtons
t = np.arange(0.0, 2.0, 0.01)
s0 = np.sin(2*np.pi*t)
s1 = np.sin(4*np.pi*t)
s2 = np.sin(8*np.pi*t)
fig, ax = plt.subplots()
l, = ax.plot(t, s0, lw=2, color='red')
fig.subplots_adjust(left=0.3)
axcolor = 'lightgoldenrodyellow'
rax = fig.add_axes([0.05, 0.7, 0.15, 0.15], facecolor=axcolor)
radio = RadioButtons(rax, ('2 Hz', '4 Hz', '8 Hz'))
def hzfunc(label):
hzdict = {'2 Hz': s0, '4 Hz': s1, '8 Hz': s2}
ydata = hzdict[label]
l.set_ydata(ydata)
plt.draw()
radio.on_clicked(hzfunc)
rax = fig.add_axes([0.05, 0.4, 0.15, 0.15], facecolor=axcolor)
radio2 = RadioButtons(rax, ('red', 'blue', 'green'))
def colorfunc(label):
l.set_color(label)
plt.draw()
radio2.on_clicked(colorfunc)
rax = fig.add_axes([0.05, 0.1, 0.15, 0.15], facecolor=axcolor)
radio3 = RadioButtons(rax, ('-', '--', '-.', ':'))
def stylefunc(label):
l.set_linestyle(label)
plt.draw()
radio3.on_clicked(stylefunc)
plt.show()
from asyncio import sleep from sanic import Sanic, response app = Sanic("DelayedResponseApp", strict_slashes=True) app.config.AUTO_EXTEND = False
from sanic.exceptions import SanicException from sanic.handlers import ErrorHandler class CustomHandler(ErrorHandler): def default(self, request, exception): # Here, we have access to the exception object
import logging from sanic import Sanic, text logging_format = "[%(asctime)s] %(process)d-%(levelname)s " logging_format += "%(module)s::%(funcName)s():l%(lineno)d: " logging_format += "%(message)s"
Install testing tools: $ pip install pytest pytest-xdist Run with xdist params: $ pytest examples/pytest_xdist.py -n 8 # 8 workers example import re import pytest
from os import getenv from raygun4py.raygunprovider import RaygunSender from sanic import Sanic from sanic.exceptions import SanicException from sanic.handlers import ErrorHandler
from sanic import Sanic, response app = Sanic("Example") @app.route("/") def handle_request(request): return response.redirect("/redirect")
Click somewhere, move the mouse, and release the mouse button. `.RectangleSelector` and `.EllipseSelector` draw a rectangle or an ellipse from the initial click position to the current mouse position (within the same axes) until the button is released
In this example, sliders are used to control the frequency and amplitude of a sine wave. See :doc:`/gallery/widgets/slider_snap_demo` for an example of having
Snapping Sliders to Discrete Values You can snap slider values to discrete values using the ``valstep`` argument. In this example the Freq slider is constrained to be multiples of pi, and the Amp slider uses an array as the ``valstep``
import asyncio from sanic import Sanic, response from sanic.config import Config from sanic.exceptions import RequestTimeout