Skip to content
Snippets Groups Projects
Commit 6e43ab5e authored by Ujjwal Sinha's avatar Ujjwal Sinha
Browse files

Added the plotting scripts and dataset

parent b2403906
Branches main
No related tags found
No related merge requests found
%% Cell type:markdown id:8960d8ff-6f5a-48b9-85e9-d315a7393ad7 tags:
Importing Pandas and Matplotlib libraries
%% Cell type:code id:e8a9175e-0940-4d29-aa69-e0e4c5568697 tags:
``` python
import pandas as pd
import matplotlib.pyplot as plt
```
%% Cell type:markdown id:5b72acb4-f08a-49cd-845a-4b451d8fd07b tags:
The %matplotlib widget magic command
%% Cell type:code id:81c64c59-7796-4b40-8f1c-120b814f7fc9 tags:
``` python
%matplotlib widget
```
%% Cell type:markdown id:a1dac6b8-a13d-4224-8119-532c039118d8 tags:
Loading the file path
%% Cell type:code id:54632c3e-5810-477d-b259-e1d7c4052d7e tags:
``` python
file_path = 'data.txt'
```
%% Cell type:markdown id:04dea8a3-2ecb-4454-8e11-047bb3ffa46d tags:
Loading the dataset from the text file
%% Cell type:code id:30ac6176-2ea5-4455-af49-c7517e11cbfb tags:
``` python
df = pd.read_csv(file_path, delim_whitespace=True)
```
%% Cell type:markdown id:f37c8db0-2158-4504-a253-95db524b84d3 tags:
Printing the column names of the dataset
%% Cell type:code id:790813c6-d660-4472-bf7b-938324d78794 tags:
``` python
print(df.columns)
```
%% Output
Index(['Serial', 'Col2', 'Exp(Col1)', 'Exp(Col1)*2', 'Exp(Col1)*4'], dtype='object')
%% Cell type:markdown id:43b1e888-8e9c-49d6-bda7-96269c155cf6 tags:
Display the column names as a list
%% Cell type:code id:0ab35eba-0a9e-4f0e-9b53-de1ec16a81cd tags:
``` python
column_names = list(df.columns)
print(column_names)
```
%% Output
['Serial', 'Col2', 'Exp(Col1)', 'Exp(Col1)*2', 'Exp(Col1)*4']
%% Cell type:markdown id:7e5203b1-5599-495e-8d7d-e3b1df88ec4f tags:
Determining the figure size in inches
%% Cell type:code id:000c1ee9-14b9-43e2-b59f-df1050932671 tags:
``` python
plt.figure(figsize=(5.5, 5.5))
```
%% Output
<Figure size 550x550 with 0 Axes>
%% Cell type:markdown id:89a74e21-04cf-4f4e-8add-64af392e455d tags:
Plotting the data
%% Cell type:code id:2dbdb2d2-81ba-46f4-9088-e6dde12988fc tags:
``` python
plt.plot(df['Serial'], df['Col2'], color='black', linewidth=2, linestyle='-', label='Col2', marker='o')
plt.plot(df['Serial'], df['Exp(Col1)'], color='blue', linewidth=2, linestyle='--', label='Exp(Col1)', marker='o')
plt.plot(df['Serial'], df['Exp(Col1)*2'], color='green', linewidth=2, linestyle='-.', label='Exp(Col1)*2', marker='o')
plt.plot(df['Serial'], df['Exp(Col1)*4'], color='red', linewidth=2, linestyle=':', label='Exp(Col1)*4', marker='o')
```
%% Output
[<matplotlib.lines.Line2D at 0x14d83ba92df0>]
%% Cell type:markdown id:ba5484a6-16d8-42fc-a268-354ac4dd38ae tags:
Customizing the plot
%% Cell type:code id:835fae71-c5a3-4383-ad08-e97988f5f2b3 tags:
``` python
plt.title('Exponential Growth of Column Data', fontsize=14)
plt.xlabel('Serial No.', fontsize=12)
plt.ylabel('Values', fontsize=12)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
plt.legend(fontsize=10)
plt.grid(True)
```
%% Cell type:markdown id:9295847d-04d5-47a3-815f-d3f492ff3e97 tags:
Setting ticks to point inwards
%% Cell type:code id:a5ff8e5c-ac1c-4f55-8857-3bc3cc824c1f tags:
``` python
plt.tick_params(axis='both', direction='in')
```
%% Cell type:markdown id:0d3b26bf-96c7-42f1-b743-4d8380e40252 tags:
plt.tight_layout()
%% Cell type:markdown id:6a86f7e4-dc72-4ff8-85b9-5d6cdf84c4c5 tags:
Show the plot
%% Cell type:code id:f7948427-0ced-42ba-9e3d-00041cd5fc1a tags:
``` python
plt.show()
```
%% Output
%% Cell type:code id:6a9f1c34-dbbf-4366-9af4-0c7b3cdbf9fd tags:
``` python
```
data.txt 0 → 100644
Serial Col2 Exp(Col1) Exp(Col1)*2 Exp(Col1)*4
1 2 2.72 5.44 10.87
2 4 7.39 14.78 29.56
3 8 20.09 40.17 80.34
4 16 54.60 109.20 218.39
5 32 148.41 296.83 593.65
6 64 403.43 806.86 1613.72
7 128 1096.63 2193.27 4386.53
8 256 2980.96 5961.92 11923.83
9 512 8103.08 16206.17 32412.34
10 1024 22026.47 44052.93 88105.86
11 2048 59874.14 119748.28 239496.57
12 4096 162754.79 325509.58 651019.17
13 8192 442413.39 884826.78 1769653.57
14 16384 1202604.28 2405208.57 4810417.14
15 32768 3269017.37 6538034.74 13076069.49
16 65536 8886110.52 17772221.04 35544442.08
17 131072 24154952.75 48309905.51 96619811.01
18 262144 65659969.14 131319938.27 262639876.55
19 524288 178482300.96 356964601.93 713929203.85
20 1048576 485165195.41 970330390.82 1940660781.64
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment