How to increase colormap/linewidth quality in streamplot Matplotlib?

To increase colormap/linewidth quality in streamplot matplotlib, we can take the following steps


  • Set the figure size and adjust the padding between and around the subplots.

  • Create a figure and a set of subplots.

  • Create x and y data points and then use np.meshgrid() to return the coordinate matrices from the coordinate vectors.

  • Find X and Y using x and y data points.

  • Create a streamplot with x, y, X and Y data points. You can increase the linewidth using the linewidth parameter in the method. Here we have used linewidth=5.

  • Create a colorbar for a ScalarMappable instance, *stream.lines*.

  • To display the figure, use Show() method.


import numpy as np
from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True

fig, ax = plt.subplots()

x, y = np.meshgrid(np.linspace(-5, 5, 20), np.linspace(-5, 5, 20))

X = y
Y = 3 * x - 4 * y

stream = ax.streamplot(x, y, X, Y,  density=1, linewidth=5, cmap='plasma', color=Y)

fig.colorbar(stream.lines, ax=ax)


It will produce the following output −

Updated on: 09-Oct-2021


Kickstart Your Career

Get certified by completing the course

Get Started