A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/style-plots-using-matplotlib/ below:

Style Plots using Matplotlib - GeeksforGeeks

Style Plots using Matplotlib

Last Updated : 26 Apr, 2025

By using style function in Matplotlib we can apply predefined themes or create custom styles which helps in making our plots interactive. We can reuse these templates to maintain consistency across multiple plots. In this article we will see how to use Matplotlib’s built-in styles and efficiently apply them to your plots.

Syntax: plt.style.use('style_name")

If we want to explore all the available styles we can print it like this:

Python
from matplotlib import style 
import matplotlib.pyplot as plt 
print(plt.style.available)

Output:

['Solarize_Light2', '_classic_test_patch', 'bmh', ----------------seaborn-whitegrid','tableau-colorblind10']

Example 1: Applying Solarize_Light2 Style Python
import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib import style 
data = np.random.randn(50) 
plt.style.use('Solarize_Light2') 
plt.plot(data) 
plt.show() 

Output:

Solarize_Light2 Example 2: Applying dark_background Style Python
import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib import style 
data = np.random.randn(50) 
plt.style.use('dark_background') 
plt.plot(data) 
plt.show() 

Output:

dark_background Example 3: Applying ggplot Style Python
import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib import style 
data = np.random.randn(50) 
plt.style.use('ggplot') 
plt.plot(data, linestyle=":", linewidth=2) 
plt.show() 

Output:

ggplot Example 4: Temporarily apply dark_background Style

Note: If we only want to use a style for a particular plot but don't want to change the global styling for all the plots, for that it provides a context manager for limiting the area of styling for a particular plot.

Python
 import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib import style 
with plt.style.context('dark_background'): 
	plt.plot(np.sin(np.linspace(0, 2 * np.pi)), 'r-o') 
plt.show() 

Output:

dark_background (temporary)

By using Matplotlib's styling features we can easily create visually appealing and consistent plots which helps in enhancing overall presentation of our data.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4