Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Define the encoding of this script (unicode)
- # -*- coding: utf-8 -*-
- # Importing the module numpy, and renaming it np
- import numpy as np
- # Importing the module matplotlib.pyplot, and renaming it plt
- import matplotlib.pyplot as plt
- # Loads data from file into variables
- # One variable for each column, this is possible thanks to unpack=True
- # It is important that the number of columns corresponds with the number of variables
- # Note that we use skiprows=1, this is because the top row is a header
- # NOTE! You can download the file example_data.txt from the following URL:
- # folk.ntnu.no/evenjc/python/example_data.txt
- Pa, C, Rh, NH3, CO, NO2 = np.loadtxt('example_data.txt', unpack=True, skiprows=1)
- # Plotting NH3, with the name "NH3", pink color, and a line width of 5 points
- plt.plot(NH3, label="NH3", color="pink", lineWidth=5)
- # Plotting CO without a name, with standard color and line width. Matplotlib will chose colors
- plt.plot(CO)
- # Places a legend. 8 is center bottom. Legend uses the label-data. See NH3 plot
- # Do a google search for "matplotlib legend" for alternative placements
- # If loc = 8 is removed, matplotlib will try to find the most suitable location
- plt.legend(loc=8)
- # Add grid to plot window
- plt.grid()
- # Redefine the bounds of your plot
- plt.ylim(10, 30)
- plt.xlim(0, 20)
- # Show plot
- plt.show()
- # If you want to save your figure to file, use savefig instead of show.
- # https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html
Add Comment
Please, Sign In to add comment