Different 3D plot from Matplotlib

40 views
Skip to first unread message

Hassan

unread,
Aug 10, 2023, 4:33:34 AM8/10/23
to pyqtgraph
Hi,

I was trying to plot a 3D mesh using PyQtGraph and realized that it gives a different graph compared to Matplotlib. The data is exactly the same for both, and the Matplotlib plot is the correct one. I was wondering why and how can I amend this. I am going to use PyQtGraph as it is much faster.
I attached the PyQtgraph plot (black background) and Matplotlib plot (white background). Here is the code for both libraries:

# Plot edges
edge_lines = []
for edge in edges:
vertex1 = vertices[edge[0] - 1]
vertex2 = vertices[edge[1] - 1]
edge_lines.append([(vertex1[0], vertex1[1], vertex1[2]),
(vertex2[0], vertex2[1], vertex2[2])])

edge_collection = Line3DCollection(edge_lines, colors='blue')
ax.add_collection3d(edge_collection)

# Set the limits to make the scene larger
ax.set_xlim(min(vertices[:, 0]), max(vertices[:, 0]))
ax.set_ylim(min(vertices[:, 1]), max(vertices[:, 1]))
ax.set_zlim(min(vertices[:, 2]), max(vertices[:, 2]))

plt.show()


# Create a PyQtGraph application
app = QtWidgets.QApplication([])

# Create a PyQtGraph OpenGL plot window
w = gl.GLViewWidget()
w.opts['distance'] = 50
w.show()
edge_item = gl.GLLinePlotItem(pos=edge_lines, color=(0, 0, 1, 1)) # Color is blue, RGBA format
w.addItem(edge_item)

# Start the PyQtGraph event loop
app.exec_()



Matplotlib.JPG
PyQtGraph.JPG
Reply all
Reply to author
Forward
0 new messages