QtDataVisualization: Setting custom colors for 3DPlots
-
Creating a custom surface plot color with respect to a set of values
So, I have successfully plotted some figures using Q3DSurface() and Q3DScatter(), and now I am trying to get something going with the coloring.What I want to accomplish is essentially plotting a color over a surface or over the points in a scatter plot.
So for example, say I plot a figure using some x, y and z values taken from some data log uploaded. These values result in a figure that visualizes a regular cylinder.
Now this is where I am struggling to find a solution. I have figured out how to build this plot, and now what I want to do is essentially plot a color over the figure with respect to another variable in this data log.
If you look at my code, i read in an x, y, z , and laser power variable. I want to plot that last variable over the figure.
I'm not 100% sure how to turn a list of data (floats) into values that could be used as colors. Matplotlib has a similar function that can do this for plotting colors over a surface.
Does Qt for Python have any way of doing this? I am having difficulties finding ways to customize colors and gradients over a figure. Any help would be appreciated.
Here is my code for scatter plot:
import sys from PySide6.QtDataVisualization import * from PySide6.QtGui import QVector3D, Qt, QLinearGradient from PySide6.QtWidgets import QApplication import pandas as pd if __name__ == "__main__": #qputenv("QSG_RHI_BACKEND", "opengl") app = QApplication(sys.argv) scatter = Q3DScatter() scatter.setFlags(scatter.flags() ^ Qt.FramelessWindowHint) file = "some_data_log.txt" vars = ['X Position (mm)', 'Y Position (mm)', 'Z Position (mm)', 'Laser Commanded Power (Watts)'] df1 = pd.read_csv(file, low_memory=False, on_bad_lines='skip', usecols=vars) df1 = df1.apply(pd.to_numeric) x = list(df1['X Position (mm)'].values) y = list(df1['Y Position (mm)'].values) z = list(df1['Z Position (mm)'].values) data = [] for i, val in enumerate(x): data.append(QScatterDataItem(QVector3D(x[i], y[i], z[i]))) series = QScatter3DSeries() series.dataProxy().addItems(data) scatter.addSeries(series) scatter.seriesList()[0].setBaseColor(Qt.Black) scatter.show() sys.exit(app.exec())
Here is the figure: