Python | Background Color of the Plot

In this article, we are going to set background color in a matplotlib figure (plot)?
Submitted by Anuj Singh, on August 12, 2020

In some cases, we can need a different background color, and therefore, in this article, we are going to convert the default white background to a different color.

Python | Background Color of the Plot (1)

Python | Background Color of the Plot (2)

Python | Background Color of the Plot (3)

Python code for background color of the plot

import matplotlib.pyplot as plt
import numpy as np

dt = 0.02
x = np.arange(-50.0, 50.0, dt)
y = np.arange(0, 100.0, dt)

plt.figure(facecolor=(0.2,0.5,0.6))
plt.plot(y, x, 'o', color='yellow')
plt.yscale('symlog')
plt.ylabel('Figure Colour')
plt.grid()

plt.figure(facecolor=(0.2,0.2,0.8))
plt.plot(y+100, x, 'o', color='yellow')
plt.ylabel('Figure Colour')
plt.grid()
plt.show()

plt.figure(facecolor=(0.8,0.5,0.8))
plt.plot(y, x, 'o', color='yellow')
plt.yscale('symlog')
plt.ylabel('Figure Colour')
plt.grid()

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.