<jupyter_start><jupyter_text>Basic usage of matplotlibMatplotlib is the module of choice whenever you want to make a niceplot.<jupyter_code># the following two lines are required inside a python script to be run on binder. They are not needed inside the notebook.

import matplotlib 
matplotlib.use('Agg')

import numpy as np
import matplotlib.pyplot as plt # this is the only line required to make plots with matplotlibt

# this line allows you to see the plot inside the notebook
%matplotlib inline 
# This is a simple example to make an scatter plot
plt.figure() # Create and empty figure
x = [3,4,5]
y = [-1,2,2]
plt.scatter(x,y) 
# This is another plot where we save the figure at the end as png file.

x = np.linspace(0,5,10)
y = x**2 

plt.figure() # creates an empty figure

plt.scatter(x,y) # scatter plot

plt.xlabel("x") 
plt.ylabel("y") 
plt.title("Simple scatter plot") 

plt.savefig("thefig.png") # Saves the figure


plt.figure()
x = np.linspace(-5.0,5.0,100)
y = 1./(1.+x**2)

plt.plot(x,y) # This time a line connect the points
plt.title(u"$\lambda$") # you can use latex

# After initializing plt.figure() you can make multiple plots 
plt.figure()
plt.plot(range(10),2*np.arange(10))
plt.plot(range(10),3*np.arange(10))
plt.scatter(range(10),3*np.arange(10)) 

# Now let's make some simple figures
# In this case: circles 

theta=np.linspace(0, 2*np.pi,50) # 50 points between 0 and 2pi

plt.figure()

plt.axis("equal")# this gives the same apparent size to the x and y axis
plt.axis("off") # this removes the axis

for i in range(5):
    # Elegir el centro del círculo
    x = 2*np.random.random()-1 # random value for the center in x
    y = 2*np.random.random()-1 # random value for the center in y
    r = np.random.random() # random value for the radius
    plt.plot(r * np.cos(theta) + x, r * np.sin(theta) + y)<jupyter_output><empty_output><jupyter_text>SubplotsYou can produce multiple plots inside the same figure.<jupyter_code>plt.figure(figsize=(10,5))
a = np.linspace(0,2*np.pi,100)

plt.subplot(2,2,1)
plt.plot(a,np.sin(a))
plt.title("sin")

plt.subplot(2,2,2)
plt.plot(a,np.cos(a))
plt.title(u"cos")

plt.subplot(2,2,3)
plt.plot(a,np.tan(a))
plt.ylim(-2,2)
plt.title(u"tan")

plt.subplot(2,2,4)
plt.plot(a,np.cos(a)**2)
plt.title(r"$\cos^2$")
plt.subplots_adjust(hspace=.5) # adjusts the horizontal space between the subplots

# this an almost empty figure, only plotting text, so that you can see what is the ordering when you call plt.subplot(5,5,k)

plt.figure(figsize=(10,10))
k = 1
for n in range(1,6):
    for d in range(1,6):
        plt.subplot(5,5,k)
        plt.plot()
        plt.text(0,0,"k="+str(k))
        plt.axis("off") # esto elimina los ejes
        plt.axis("equal")
        k = k + 1

# Drawing some roses
# http://en.wikipedia.org/wiki/Rose_%28mathematics%29
plt.figure(figsize=(10,10))
k = 1
for n in range(1,6):
    for d in range(1,6):
        plt.subplot(5,5,k)
        kah = n/d
        a = np.linspace(0,2*d*np.pi,200)
        r = np.sin(kah * a)
        x = r * np.cos(a)
        y = r * np.sin(a)
        plt.plot(x,y)
        plt.axis("off") 
        plt.axis("equal")
        k = k + 1
plt.show()<jupyter_output><empty_output><jupyter_text>Legends<jupyter_code># Adding legends to different lines in the same plot
plt.figure()
x = np.linspace(0,2*np.pi,20)
plt.plot(x,np.sin(x),"or-",label='sin(x)')
plt.plot(x,np.cos(x),"ob-",label='cos(x)')
plt.legend()
plt.axis([0,2*np.pi,-1,1])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15391254315304947, 'fraction_numerical': 0.03423475258918297, 'mean_word_length': 3.8157894736842106, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '20802', 'license': 'MIT', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1357, 'n_words': 363, 'path': 'ejercicios/04/04_plotting.ipynb', 'repo_name': 'restom10/Hw2', 'size': '3476'}