Matplotlib.axes.Axes.get_sketch_params() in Python

Matplotlib.axes.Axes.get_sketch_params() in Python

The get_sketch_params() method in the matplotlib.axes.Axes class is used to get the sketch parameters for the paths. Sketching is a feature in Matplotlib that allows paths to be "sketched", i.e., given a hand-drawn appearance. This is primarily useful for disguising the fact that the data being plotted or represented is actually precise, computer-generated, and not hand-drawn.

The method's signature is:

Axes.get_sketch_params() 

This method returns a tuple containing three values:

  1. scale: The amplitude of the wiggle perpendicular to the source line.
  2. length: The length of the wiggle along the line.
  3. randomness: A random seed or generator that determines the wiggle.

Here's a simple example to illustrate the use of sketching and how to get the sketch parameters:

import numpy as np import matplotlib.pyplot as plt # Create a simple curve t = np.linspace(0, 10, 100) y = np.sin(t) fig, ax = plt.subplots() # Set sketch parameters: (scale, length, randomness) ax.set_sketch_params(1, 10, None) ax.plot(t, y) # Get and print sketch parameters sketch_params = ax.get_sketch_params() print(f"Sketch Parameters: {sketch_params}") plt.show() 

In the example above, we first set the sketch parameters for the Axes instance using set_sketch_params(). Then, we plot a sine curve that will appear as if it's hand-drawn due to the sketching. Lastly, we retrieve and print the sketch parameters using get_sketch_params().


More Tags

r-faq camunda script-task babeljs launch-configuration primeng python-unicode google-cloud-endpoints pytest celery

More Programming Guides

Other Guides

More Programming Examples