Skip to content
Related Articles

Related Articles

Matplotlib.pyplot.xkcd() in Python
  • Last Updated : 21 Apr, 2020

One of the main process in Data Science is Data Visualization. Dat 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 numy and sideby framework that’s why it is fast and efficient. It is open source and have ahuge cmmunity 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.

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :
matplotlib.pyplot.xkcd()

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

python-matplotlib-xkcd

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :