-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem2_MoreFunctions.py
57 lines (43 loc) · 2.34 KB
/
Problem2_MoreFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# Put in a function
# A) put all of this code into a function that takes a few arguments, namely the marker, markersize, lignstyle and color call this function plot_quasars
# B) have all the arguments be default arguments set to the defaults that they are within plot currently.
# C) change the name of the figure depending on the combination of arguments given so that with each combination a new figure name is produced
# D) Try this out with many different combinations of arguments. Research the plot command to try to change the marker, markersize, linestyle, etc. appropriately
# Author: Jake VanderPlas
# License: BSD
# The figure produced by this code is published in the textbook
# "Statistics, Data Mining, and Machine Learning in Astronomy" (2013)
# For more information, see http://astroML.github.com
# To report a bug or issue, use the following forum:
# https://groups.google.com/forum/#!forum/astroml-general
from matplotlib import pyplot as plt
from astroML.datasets import fetch_dr7_quasar
#----------------------------------------------------------------------
# This function adjusts matplotlib settings for a uniform feel in the textbook.
# Note that with usetex=True, fonts are rendered with LaTeX. This may
# result in an error if LaTeX is not installed on your system. In that case,
# you can set usetex to False.
from astroML.plotting import setup_text_plots
def plot_quasars(marker='.', markersize=2, linestyle='none', color='black'):
setup_text_plots(fontsize=8, usetex=True)
#------------------------------------------------------------
# Fetch the quasar data
data = fetch_dr7_quasar()
# select the first 10000 points
data = data[:10000]
r = data['mag_r']
i = data['mag_i']
z = data['redshift']
#------------------------------------------------------------
# Plot the quasar data
fig, ax = plt.subplots(figsize=(5, 3.75))
ax.plot(z, r - i, marker=marker, markersize=markersize, linestyle=linestyle, color=color)
ax.set_xlim(0, 5)
ax.set_ylim(-0.5, 1.0)
ax.set_xlabel(r'${\rm redshift}$')
ax.set_ylabel(r'${\rm r-i}$')
fig.savefig("problem2" + str(marker) + str(markersize) + str(linestyle) + str(color) + ".png")
plot_quasars()
plot_quasars(markersize=2, linestyle="solid", color="#0effff")
plot_quasars(marker="*", markersize=10, color="#0effff")