- #1
Martyn Arthur
- 118
- 20
TL;DR Summary: How to understand the code determining the plot
Hi; this is the code I have been given for a H-R diagram of M35; I understand the inversion concept.. The plot is below. I am trying to understand the code that creates its position and size and how to alter it to a more 'acceptable' format please.
Thanks
Martyn
Hi; this is the code I have been given for a H-R diagram of M35; I understand the inversion concept.. The plot is below. I am trying to understand the code that creates its position and size and how to alter it to a more 'acceptable' format please.
Thanks
Martyn
Python:
# Enter your code for your CMD plot here.
import pandas as pd # Pandas is a common package for handling data as tables known as DataFrames
import numpy as np # Numpy has essential tools for manipulating lists of data
import matplotlib.pyplot as plt # matplotlib is the tool for plotting data
#ClusterData = pd.read_csv("MeasurementsM38.xls", sep = r"\s+") # Open the data file
#Above # as file is already open
display(ClusterData)
display(ClusterData.head(5)) # display the top 5 lines to check the data has been imported correctly
print(ClusterData.columns) # Print the column names for the DataFrame
keep_list = ClusterData['B_V'] < 2.0 # Questions which rows have a value less than 2.0 in the column B-V
print(keep_list) # Print this list
print('Length of ClusterData dataframe = ', len(ClusterData)) # Print the length of the DataFrame
ClusterData_red_removed = ClusterData[keep_list] # Save a new DataFrame based on the Boolean operator list
print('Length of ClusterData_red_removed dataframe = ', len(ClusterData_red_removed)) # Print the length
plt.rcParams['figure.figsize'] = [12, 8] # Set figure.figsize to be 12 inches wide and 8 inches high.
plt.scatter( # pyplot.scatter() function
ClusterData_red_removed["B_V"], # Required input - x values
ClusterData_red_removed["Vmag"], # Required input - y values
c = ClusterData_red_removed["B_V"], # Setting colour based on B-V colour
cmap = "coolwarm", # Setting the colour map to use
s = 3) # Setting datapoint size
plt.ylim((13, 0)) # Set y axis limits, with the higher number first to invert the axis
plt.title('Colour Magnitude diagram of M35 ') # Set plot title
plt.xlabel('Colour index (B_V)') # Set x axis label
plt.ylabel('Apparent V magnitude') # Set y axis label
plt.show() # Show the plot
Last edited by a moderator: