The Wayback Machine - http://web.archive.org/web/20221119183716/https://www.geeksforgeeks.org/matplotlib-pyplot-xkcd-in-python/
Skip to content
Related Articles

Related Articles

Matplotlib.pyplot.xkcd() in Python

Improve Article
Save Article
  • Last Updated : 24 Feb, 2022
Improve Article
Save Article

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.xcorr() 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. 

ParameterDatatypeDescription
scalefloatThe amplitude of the wiggle perpendicular to the source line.
lengthfloatThe length of the wiggle along the line.
randomnessfloatThe 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

 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!