2

I'm working on an antenna 3D polar plot program which need to render real-time plot.

Trying to implement

Things I'm using:

  • Python 3.11.9
  • PyQt6 6.9.1
  • PyQt6-WebEngine-Qt6 6.9.2
  • plotly 6.3.1

Issue: The code can generate a correct HTML file that displays the plot properly in a browser, but QWebEngine fails to load it and shows a white screen when there are more than 250 × 181 points. My dataset has 360 × 181 points.

Is there any way to fix this? I’m also open to using other libraries that can provide better performance or results.

Expected:

Expected Result

Result:

White Screen

My Code:

import sys
import numpy as np
import plotly.graph_objects as go
from PyQt6.QtWidgets import QApplication, QVBoxLayout, QWidget
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWebEngineCore import QWebEnginePage

# ---------- Data Size ----------
n_theta = 181 
n_phi = 251

theta = np.linspace(0, 2 * np.pi, n_theta)
phi = np.linspace(0, np.pi, n_phi)

theta, phi = np.meshgrid(theta, phi) 

# ---------- Example Data ----------
r = [1 for i in range(n_theta)]

x = r * np.sin(phi) * np.cos(theta)
y = r * np.sin(phi) * np.sin(theta)
z = r * np.cos(phi)

# ---------- Plotly Surface ----------
fig = go.Figure(
    data=go.Surface(
        x=x, y=y, z=z,
        colorscale='Viridis',
        showscale=True,
        contours=dict(
            x=dict(show=True, color='black'),
            y=dict(show=True, color='black'),
            z=dict(show=True, color='black')
        ),
        lighting=dict(ambient=0.8, diffuse=0.8),
        lightposition=dict(x=100, y=200, z=100)
    )
)

fig.update_layout(
    title='3D Antenna Radiation Pattern',
    scene=dict(
        xaxis_title='X',
        yaxis_title='Y',
        zaxis_title='Z',
        aspectmode='data'
    ),
    margin=dict(l=0, r=0, t=40, b=0)
)

# ---------- PyQt Window ----------
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle("3D Antenna Pattern in PyQt6")
layout = QVBoxLayout()
window.setLayout(layout)

webview = QWebEngineView()
webview.setHtml(fig.to_html(include_plotlyjs='cdn'))
layout.addWidget(webview)

window.resize(900, 700)
window.show()
sys.exit(app.exec())

3
  • did you try to write in file and check if it works in real web browser? Commented Oct 19 at 2:12
  • @furas Yes, it works fine in Chrome and Edge. Based on my research, QWebEngine uses an outdated browser engine with relatively poor performance, which is why it struggles to render complex plots. Commented Oct 20 at 13:43
  • there is Python bindings for the Chromium Embedded Framework (CEF) which should allow to use Chrome engine in GUi. Maybe it could help. There is even example for PyQT but code can be long. Commented Oct 20 at 14:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.