Python | Themeriver Stackplot using Matplotlib

In this tutorial, we are going to learn how to create a Theme River Plot in python using matplotlib?
Submitted by Anuj Singh, on August 03, 2020

From the family of stack plots, Theme River plot is a type where stack is generated with symmetry along the x=0 (x axis). Using Matplotlib command baseline='sym' in matplotlib.pyplot.stackplot will create a Theme-River Stack Plot.

Illustration:

Example 1:

Python | themeriver stackplot (1)

Python | themeriver stackplot (2)

Python | themeriver stackplot (3)

Example 2:

Python | themeriver stackplot (4)

Python | themeriver stackplot (5)

Python | themeriver stackplot (6)

Python code for themeriver stackplot using matplotlib

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(100)
y1 = np.random.randint(20,35,100)
y2 = np.tan(x/10)
y3 = np.sin(x)*10

y = np.vstack([y1, y2, y3])

labels = ["F1 ", "F2", "F3"]

####--------------------------------------####
####           Illustration 1             ####
plt.figure()
plt.stackplot(x, y1, y2, y3, labels=labels, baseline='sym')
plt.legend(loc='upper left')
plt.xlabel('Number Progression')
plt.ylabel('Stack')
plt.title('Theme River Stack Plot Example')
plt.ylim(-50,50)
plt.show()

plt.figure()
plt.stackplot(x, y1, y2, y3, labels=labels, baseline='sym', colors=['pink','yellow','y'])
plt.legend(loc='upper left')
plt.xlabel('Number Progression')
plt.ylabel('Stack')
plt.title('Theme River Stack Plot Colour choice')
plt.ylim(-50,50)
plt.show()

plt.figure()
plt.stackplot(x, y1, y2, y3, labels=labels, color='y',  baseline='sym')
plt.legend(loc='upper left')
plt.xlabel('Number Progression')
plt.ylabel('Stack')
plt.title('Theme River Stack Plot One Colour')
plt.ylim(-50,50)
plt.show()

####--------------------------------------####
####           Illustration 2             ####
x = [1, 2, 3, 4, 5]
y1 = [1, 3, 1, 2, 4]
y2 = [0, 4, 4, 5, 1]
y3 = [1, 3, 8, 3, 1]

y = np.vstack([y1, y2, y3])

labels = ["F1 ", "F2", "F3"]

plt.figure()
plt.stackplot(x, y1, y2, y3, labels=labels, baseline='sym')
plt.legend(loc='upper left')
plt.xlabel('Number Progression')
plt.ylabel('Stack')
plt.title('Theme River Stack Plot Example')
plt.show()

plt.figure()
plt.stackplot(x, y1, y2, y3, labels=labels, baseline='sym', colors=['pink','yellow','y'])
plt.legend(loc='upper left')
plt.xlabel('Number Progression')
plt.ylabel('Stack')
plt.title('Theme River Stack Plot Colour choice')
plt.show()

plt.figure()
plt.stackplot(x, y1, y2, y3, labels=labels, color='y',  baseline='sym')
plt.legend(loc='upper left')
plt.xlabel('Number Progression')
plt.ylabel('Stack')
plt.title('Theme River Stack Plot One Colour')
plt.show()

Output:

Output is as figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.