Skip to content

Sphinx Plot Directive: PyVista and Matplotlib #5951

Answered by tkoyama010
adtzlr asked this question in Q&A
Discussion options

You must be logged in to vote

@adtzlr PyVista supports Matplotlib plots in CharMPL. I recommend to plot Matplotlib results with the PyVista plot directives.

import pyvista as pv
import numpy as np
import matplotlib.pyplot as plt

w = 3
Y, X = np.mgrid[-w:w:100j, -w:w:100j]
U = -1 - X**2 + Y
V = 1 + X - Y**2
speed = np.sqrt(U**2 + V**2)

f, ax = plt.subplots()
strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, cmap='autumn')
_ = f.colorbar(strm.lines)
_ = ax.set_title('Streamplot with varying Color')
plt.tight_layout()

chart = pv.ChartMPL(f)
chart.show()

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@adtzlr
Comment options

@adtzlr
Comment options

@MatthewFlamm
Comment options

@adtzlr
Comment options

Answer selected by tkoyama010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants