~~NOTRANS~~ {{indexmenu_n>700}} ====== Plotting ====== It's quite difficult - practically impossible - to perceive data from rows and columns with numerical data. This holds true for complex (scientific) data; but also for much simpler data, e.g. temperature records over time. Graphical plots allow fast perception. That makes plots very important - also for debugging while development. ===== Plot Types ===== There are many plot types, you can select from. See https://datavizcatalogue.com/ ===== Terminal / Command Line ===== [[http://www.gnuplot.info/|Gnuplot]] is a portable command-line tool for creating plots. Usually, comma seperated value (CSV) files are used as input, see [[devop:csv|comma separated values]]. But it's also possible to plot from binary data files. ===== C++ ===== Following plotting libraries might be used for creating (debug) plot files. First some meta results, which already give a good overview: * https://gasparri.org/2019/12/06/best-plot-and-charting-c-packages-for-data-visualization/ * https://www.researchgate.net/post/What_are_the_best_plot_and_charting_C_package_which_can_be_used_for_data_visualization * https://stackoverflow.com/questions/4283731/plotting-package-for-c Here some (additional) links: * sciplot * https://sciplot.github.io/ * https://github.com/sciplot/sciplot * Matplot++ * https://alandefreitas.github.io/matplotplusplus/ * https://github.com/alandefreitas/matplotplusplus * VTK * https://vtk.org/ * https://gitlab.kitware.com/vtk/vtk * https://kitware.github.io/vtk-examples/site/Cxx/Plotting/LinePlot/ * PLplot * https://plplot.sourceforge.net/ * https://github.com/ABRG-Models/morphologica * https://github.com/thclark/cpplot * Matplotlib-Cpp - requires python * https://github.com/lava/matplotlib-cpp * Immediate Mode Plotting (implot) * https://github.com/epezent/implot * Dear ImGui: https://github.com/ocornut/imgui ===== Python ===== A python script/program allowing interactive commands is better suited for experimenting/development. However, C++ developers might use python when compiling their code as python module with bindings, e.g. with [[https://pybind11.readthedocs.io/|pybind11]]. Interface functions might utilize [[https://numpy.org/|numpy]] or [[https://eigen.tuxfamily.org/|Eigen]], see https://pybind11.readthedocs.io/en/stable/advanced/cast/eigen.html In python, there are several plot libraries available: * Matplotlib * https://matplotlib.org/ * https://github.com/matplotlib/matplotlib * PyQtGraph - builds on Qt * https://www.pyqtgraph.org/ * https://github.com/pyqtgraph/pyqtgraph * seaborn * https://seaborn.pydata.org/ * https://github.com/mwaskom/seaborn i really like colored heatmaps: * https://stackoverflow.com/questions/33282368/plotting-a-2d-heatmap * https://github.com/DingWB/PyComplexHeatmap * https://matplotlib.org/stable/gallery/images_contours_and_fields/image_annotated_heatmap.html * https://seaborn.pydata.org/examples/spreadsheet_heatmap.html ===== Colormaps ===== Colormaps are used for visualizing or mapping mostly linear or grayscale data. IMHO, ''jet'' is very appealing for linear or logarithmic data. matplotlibs' documentation shows many colormaps: https://matplotlib.org/stable/tutorials/colors/colormaps.html From technical point of view, ''turbo'' is an improved alternative for ''jet'', see https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html Other colormaps like ''viridis'', ''plasma'' or ''inferno'' provide perceptually uniform sequential lightness. Here an interesting video on this topic: https://www.youtube.com/watch?v=xAoljeRJ3lU In SDR and signal processing, such colormaps are used to visualize the power (or energy) in one single pixel to allow [[https://en.wikipedia.org/wiki/Spectrogram|spectrogram]] plots, which already use x and y axes for time and frequency. For sure, there are usages in many other fields. ==== Cyclic colormaps ==== Circular data, e.g. phase values, should be treated special - as -180° equals +180°. //Cyclic// colormaps like ''twilight'' or ''hsv'' are for that case. These colormaps are ideally viewed on circle like here: https://stackoverflow.com/questions/62531754/how-to-draw-a-hsv-color-wheel-using-matplotlib - and not on a ruler. ==== Other links ==== * https://blog.habrador.com/2023/04/colormaps-overview-code-implementations-rainbow-virids.html * https://stackoverflow.com/questions/7706339/grayscale-to-red-green-blue-matlab-jet-color-scale