Running the code

Following our discussion on working with a scientific project in PyCharm, in the main.py file, we will input the following sample code:

import numpy as np
import matplotlib.pyplot as plt


N = 100
x = np.random.normal(0, 1, N)
y = np.random.normal(2, 3, N)

plt.hist(x, alpha=0.5, label='x')
plt.hist(y, alpha=0.5, label='y')
plt.legend(loc='upper right')
plt.show()

Using NumPy, we are simply creating two sample 100-element datasets from normal distributions (x from a distribution with a mean of 0 and a standard deviation of 1, y from a distribution with a mean of 2 and a standard deviation of 3). Then, we draw their corresponding histograms using Matplotlib.

Now, execute the program. You will see the corresponding output appear in your project window, similar to the following screenshot (the histograms might be somewhat different from my own due to randomness):

An example scientific project in PyCharm

Note that, by default, a scientific project might be run in the Python Console (as opposed to being run via the Run panel that we've seen in the previous examples in this book). Additionally, you can right-click on the background of the editor and choose Run 'SciTest' to run the program normally via the Run panel. You can also set the default run configuration of your project by accessing the Edit Configurations feature, which is located in the top window toolbar, as illustrated here:

Editing run configurations in PyCharm

You might have noticed that the generated plot is being opened in a panel called SciView. This panel is a powerful feature that's specific to PyCharm's scientific projects. For this reason, we are saving it as a topic for the next chapter.

Additionally, we also have the Documentation panel in our project window. This panel is likely to be located directly below the SciView panel (similar to the preceding screenshot) and be a part of Scientific Mode in PyCharm. It is also one of our discussion topics in the Understanding the advanced features of PyCharm's scientific projects section of this chapter, but for now, we will consider Scientific Mode in more depth.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.36.30