Use a scripting language for a comfortable C ++ life 5 --Use the Spyder integrated environment to check numerical data-

Drawing a graph may be useful for checking numerical data. If you're a Python user, you're probably being introduced to a library called matplotlib.

However, when using C ++, it seems that it is not common to use a graph library that can draw like MATLAB or matplotlib as standard. [Note](I think that there are many people who use a graph library that can draw like MATLAB or matplotlib even if they use C ++. However, it is empirical if it is not common know-how for all C ++ users. I feel it.)

Therefore, this time, I will introduce to C ++ users to handle numerical data using the Spyder integrated environment. (For those who are familiar with tools such as MATLAB and R, this is an option. Only one will be added)

In a numerical calculation program Program development does not end just because it compiles, builds, and runs. The task of confirming that the value of the result of execution is appropriate is, so to speak, the beginning of the task. Calculate using the input that tells you what value should be returned.

** Let's first check with a simple example that we know is correct **

There are many ways to verify the validity of a numerical calculation program, no matter how trivial it may be. Solving many problems for which you know the answer will help you find the problem. Makes the matrix of calculation results easier to see. Display Python's Spyder integrated environment using numpy, matplotlib, etc. At the trial and error stage, use an interactive environment to verify validity.

** Let's try a slightly more difficult example **

(Addition required)

** Check the results with noisy data **

(Addition required)

Checking these tasks without a tool like Matplotlib is a hassle. No matter how good you are at coding C ++, you should master tools other than C ++. Those who can make that much graph in C ++ should spend their effort in more recognized areas.

Matplotlib

    1. First, let's look at an example of what you can do with a library such as Matplotlib.

See many examples of Matplotlib. Then there should be something similar to what you want to draw.

  1. Next, let's learn how to replace the input data. In my case, if I receive a matrix of the output of other programs numpy.loadtxt()

If you receive an image file cv2.imread() Is used.

Replacing the input data in this way is the first step in strengthening the power of data analysis.

    1. Let's try many examples using matplotlib with scikit-learn and scikit-image. Let's run a number of examples in scikit-learn and scikit-image. All the examples provided on these sites are with data. So let's run many of those examples. Experience how matplotlib makes multiple graphs easier to read on a single plot.
  1. Apply the graph-creating ability you have acquired in this way to your problem.

May you proceed with your numerical calculations and get good results.

** Reasons why you shouldn't force graphs in OpenCV **

There is an example of handling numerical data with OpenCV imshow () and imwrite () and graphing it. However, there are various challenges. ・ You have to write the code to make it in the range of 0-255. -There is no colorbar that indicates the value. -There is no way to make it easier to understand the difference between 100 and 110 and the difference between 200 and 210. ・ It is troublesome to make it easy to see the difference between 0 and 1. ・ Every time you add a function to create a nice graph You end up carrying your own library that you have to maintain. One of the techniques I often use when I have to create a graph from C / C ++ If you give an argument with a python script, create a graph and save it. It system("python myscript.py datafile.txt") And so on. By doing so, you will not have to forcibly write the array data in the grayscale image of 0-225 with the C / C ++ source code.

[note] When using C ++, it seems that common libraries that everyone cares about are not very popular due to different operating systems in the development environment and problems such as licensing. You can see that C ++ supports any type of CPU and OS from embedded to high-end, and there are unavoidable circumstances because the GUI library is also different. For some C ++ users, it can be seen that they are having trouble checking the data and validity without knowing the useful functions of other software languages.

MATLAB is very useful as long as you can maintain your license. However, once you move a department within your organization, the license becomes unavailable immediately.

Recommended Posts

Use a scripting language for a comfortable C ++ life 5 --Use the Spyder integrated environment to check numerical data-
Use a scripting language for a comfortable C ++ life
Use a scripting language for a comfortable C ++ life 3-Leave graphing to matplotlib-
Use a scripting language for a comfortable C ++ life-OpenCV-Port Python to C ++-
Let's use a scripting language for a comfortable C ++ life 2 Automatically generate C ++ source
Use a scripting language for a comfortable C ++ life 4-Use your own C ++ library from a scripting language-
Let's use a scripting language for a comfortable C ++ life 6-How about developing a program as a library for Python?
Prepare a programming language environment for data analysis
When the Spyder integrated environment fails to work
A note for embedding the scripting language in a bash script
Build a Python environment and transfer data to the server
[Introduction to Python] How to use the in operator in a for statement?
A story about trying to improve the testing process of a system written in C language for 20 years
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
Add syntax highlighting for the Kv language to Spyder in the Python IDE
Tips for Python beginners to use the Scikit-image example for themselves 9 Use from C
[Development environment] How to create a data set close to the production DB
[C language] How to use the crypt function on Linux [Password hashing]
How to use "deque" for Python data
Instructions for connecting Google Colab. To the local runtime in a Windows environment
[Introduction to Python] How to get the index of data with a for statement