Open In App

Matplotlib.pyplot.xkcd() in Python

Improve
Improve
Like Article
Like
Save
Share
Report

One of the main process in Data Science is Data Visualization. Data Visualization refers to present a dataset in the form of graphs and pictures. We can identify upcoming trend by observing these Graphs.

Python provides us with an amazing Data Visualization library in it which is Matplotlib which was developed by John Hunter (1968-2012). Matplotlib is built on numpy and sideby framework that’s why it is fast and efficient. It is open-source and has huge community support.It possesses the ability to work well with many operating systems and graphic backends. 

matplotlib.pyplot.xkcd() function

Generally, plots generated by matplotlib are very perfect as well as monotonous. Observing these graphs are not that much fun. Matplotlib provides a library that can make these graphs a bit interesting and draws graphs in comic style. These graphs are interesting and everyone would love to study through these graphs. 

For Example :  

python-matplotlib

Parameters :
All three parameters in xkcd() are optional. 

Parameter Datatype Description
scale float The amplitude of the wiggle perpendicular to the source line.
length float The length of the wiggle along the line.
randomness float The scale factor by which the length is shrunken or expanded.

Example 1: 

Lets generate a sine wave in xkcd() style  

Python3




import numpy as np
import matplotlib.pyplot as plt
 
time = np.arange(0, 10, 0.1);
amplitude = np.sin(time)
 
with plt.xkcd():
    plt.plot(time, amplitude)
    plt.title('Sine wave')
    plt.xlabel('Time')
    plt.ylabel('Amplitude = sin(time)')
    plt.axhline(y = 0, color ='k')
     
    plt.show()


Output : 

matplotlib.pyplot.xkcd()

Example 2:

Python3




import numpy as np
import matplotlib.pyplot as plt
 
 
with plt.xkcd():
    plt.plot([1, 2, 3, 4], [5, 4, 9, 2])
    plt.title('matplotlib.pyplot.xkcd()')
    plt.axhline(y = 0, color ='k')
     
    plt.show()


Output:

python-matplotlib-xkcd

 



Last Updated : 09 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads