2025-0415 Code after lecture
This commit is contained in:
		
							parent
							
								
									bb72e110a5
								
							
						
					
					
						commit
						27608afa99
					
				
					 11 changed files with 10596 additions and 2 deletions
				
			
		
							
								
								
									
										62
									
								
								bigos/lecture20250415/matplotlib/linestyles.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								bigos/lecture20250415/matplotlib/linestyles.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,62 @@
 | 
			
		|||
 | 
			
		||||
# https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html
 | 
			
		||||
 | 
			
		||||
import matplotlib.pyplot as plt
 | 
			
		||||
import numpy as np
 | 
			
		||||
 | 
			
		||||
linestyle_str = [
 | 
			
		||||
     ('solid', 'solid'),      # Same as (0, ()) or '-'
 | 
			
		||||
     ('dotted', 'dotted'),    # Same as ':'
 | 
			
		||||
     ('dashed', 'dashed'),    # Same as '--'
 | 
			
		||||
     ('dashdot', 'dashdot')]  # Same as '-.'
 | 
			
		||||
 | 
			
		||||
linestyle_tuple = [
 | 
			
		||||
     ('loosely dotted',        (0, (1, 10))),
 | 
			
		||||
     ('dotted',                (0, (1, 5))),
 | 
			
		||||
     ('densely dotted',        (0, (1, 1))),
 | 
			
		||||
 | 
			
		||||
     ('long dash with offset', (5, (10, 3))),
 | 
			
		||||
     ('loosely dashed',        (0, (5, 10))),
 | 
			
		||||
     ('dashed',                (0, (5, 5))),
 | 
			
		||||
     ('densely dashed',        (0, (5, 1))),
 | 
			
		||||
 | 
			
		||||
     ('loosely dashdotted',    (0, (3, 10, 1, 10))),
 | 
			
		||||
     ('dashdotted',            (0, (3, 5, 1, 5))),
 | 
			
		||||
     ('densely dashdotted',    (0, (3, 1, 1, 1))),
 | 
			
		||||
 | 
			
		||||
     ('dashdotdotted',         (0, (3, 5, 1, 5, 1, 5))),
 | 
			
		||||
     ('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
 | 
			
		||||
     ('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def plot_linestyles(ax, linestyles, title):
 | 
			
		||||
    X, Y = np.linspace(0, 100, 10), np.zeros(10)
 | 
			
		||||
    yticklabels = []
 | 
			
		||||
 | 
			
		||||
    for i, (name, linestyle) in enumerate(linestyles):
 | 
			
		||||
        ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black')
 | 
			
		||||
        yticklabels.append(name)
 | 
			
		||||
 | 
			
		||||
    ax.set_title(title)
 | 
			
		||||
    ax.set(ylim=(-0.5, len(linestyles)-0.5),
 | 
			
		||||
           yticks=np.arange(len(linestyles)),
 | 
			
		||||
           yticklabels=yticklabels)
 | 
			
		||||
    ax.tick_params(left=False, bottom=False, labelbottom=False)
 | 
			
		||||
    ax.spines[:].set_visible(False)
 | 
			
		||||
 | 
			
		||||
    # For each line style, add a text annotation with a small offset from
 | 
			
		||||
    # the reference point (0 in Axes coords, y tick value in Data coords).
 | 
			
		||||
    for i, (name, linestyle) in enumerate(linestyles):
 | 
			
		||||
        ax.annotate(repr(linestyle),
 | 
			
		||||
                    xy=(0.0, i), xycoords=ax.get_yaxis_transform(),
 | 
			
		||||
                    xytext=(-6, -12), textcoords='offset points',
 | 
			
		||||
                    color="blue", fontsize=8, ha="right", family="monospace")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
fig, (ax0, ax1) = plt.subplots(2, 1, figsize=(7, 8), height_ratios=[1, 3],
 | 
			
		||||
                               layout='constrained')
 | 
			
		||||
 | 
			
		||||
plot_linestyles(ax0, linestyle_str[::-1], title='Named linestyles')
 | 
			
		||||
plot_linestyles(ax1, linestyle_tuple[::-1], title='Parametrized linestyles')
 | 
			
		||||
 | 
			
		||||
plt.show()
 | 
			
		||||
							
								
								
									
										3
									
								
								bigos/lecture20250415/matplotlib/matplotlib links.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								bigos/lecture20250415/matplotlib/matplotlib links.txt
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
Main examples site
 | 
			
		||||
https://matplotlib.org/stable/gallery/index.html
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
# pip install matpplotlib
 | 
			
		||||
 | 
			
		||||
from matplotlib import pyplot as plt
 | 
			
		||||
labels = [ "Python", "Java", "HTML", "C#", "Javascript"]
 | 
			
		||||
data = [95,80,65,80,95]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								bigos/lecture20250415/numpy/numpy-links.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								bigos/lecture20250415/numpy/numpy-links.txt
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
Basic Tutorial
 | 
			
		||||
https://numpy.org/doc/stable/user/absolute_beginners.html
 | 
			
		||||
							
								
								
									
										3
									
								
								bigos/lecture20250415/plotly/plotly-links.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								bigos/lecture20250415/plotly/plotly-links.txt
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
Main site
 | 
			
		||||
https://plotly.com/python/
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -6,7 +6,7 @@ import pprint
 | 
			
		|||
 | 
			
		||||
def get_joke():
 | 
			
		||||
 | 
			
		||||
    url = "http://api.icndb.com/jokes/random?limitTo=nerdy "
 | 
			
		||||
    url = "https://api.chucknorris.io/jokes/random?limitTo=nerdy "
 | 
			
		||||
 | 
			
		||||
    response = urllib.request.urlopen(url)
 | 
			
		||||
    result = json.loads(response.read())
 | 
			
		||||
| 
						 | 
				
			
			@ -24,6 +24,6 @@ joke = get_joke()
 | 
			
		|||
 | 
			
		||||
#prettyPrintDictionary(joke)
 | 
			
		||||
 | 
			
		||||
print(joke['value']['joke'])
 | 
			
		||||
print(joke['value'])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										16
									
								
								bigos/lecture20250415/urllib/iss/iss-1.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								bigos/lecture20250415/urllib/iss/iss-1.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
 | 
			
		||||
import json
 | 
			
		||||
import urllib.request
 | 
			
		||||
import turtle
 | 
			
		||||
 | 
			
		||||
import pprint
 | 
			
		||||
 | 
			
		||||
import time
 | 
			
		||||
 | 
			
		||||
url = 'http://api.open-notify.org/astros.json'
 | 
			
		||||
response = urllib.request.urlopen(url)
 | 
			
		||||
result = json.loads(response.read())
 | 
			
		||||
 | 
			
		||||
print(result)
 | 
			
		||||
 | 
			
		||||
pprint.pprint(result)
 | 
			
		||||
							
								
								
									
										37
									
								
								bigos/lecture20250415/urllib/iss/iss-3.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								bigos/lecture20250415/urllib/iss/iss-3.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
 | 
			
		||||
import json
 | 
			
		||||
import urllib.request
 | 
			
		||||
import turtle
 | 
			
		||||
 | 
			
		||||
import time
 | 
			
		||||
 | 
			
		||||
url = 'http://api.open-notify.org/astros.json'
 | 
			
		||||
response = urllib.request.urlopen(url)
 | 
			
		||||
result = json.loads(response.read())
 | 
			
		||||
import pprint
 | 
			
		||||
 | 
			
		||||
print(result)
 | 
			
		||||
 | 
			
		||||
print("People on the ISS: ",result['number'])
 | 
			
		||||
people = result['people']
 | 
			
		||||
#print(people)
 | 
			
		||||
 | 
			
		||||
#for person in people:
 | 
			
		||||
#    print(person)
 | 
			
		||||
 | 
			
		||||
for person in people :
 | 
			
		||||
    print(person['name'])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
url = 'http://api.open-notify.org/iss-now.json'
 | 
			
		||||
response = urllib.request.urlopen(url)
 | 
			
		||||
result = json.loads(response.read())
 | 
			
		||||
 | 
			
		||||
print(result)
 | 
			
		||||
 | 
			
		||||
location = result['iss_position']
 | 
			
		||||
latitude = location['latitude']
 | 
			
		||||
longitude = location['longitude']
 | 
			
		||||
 | 
			
		||||
print('Latitude:  ',latitude)
 | 
			
		||||
print('Longitude: ',longitude)
 | 
			
		||||
							
								
								
									
										55
									
								
								bigos/lecture20250415/urllib/iss/iss-4.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								bigos/lecture20250415/urllib/iss/iss-4.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,55 @@
 | 
			
		|||
 | 
			
		||||
import json
 | 
			
		||||
import urllib.request
 | 
			
		||||
import turtle
 | 
			
		||||
 | 
			
		||||
import time
 | 
			
		||||
 | 
			
		||||
url = 'http://api.open-notify.org/astros.json'
 | 
			
		||||
response = urllib.request.urlopen(url)
 | 
			
		||||
result = json.loads(response.read())
 | 
			
		||||
 | 
			
		||||
print(result)
 | 
			
		||||
 | 
			
		||||
print("People on the ISS: ",result['number'])
 | 
			
		||||
people = result['people']
 | 
			
		||||
#print(people)
 | 
			
		||||
 | 
			
		||||
#for person in people:
 | 
			
		||||
#    print(person)
 | 
			
		||||
 | 
			
		||||
for person in people :
 | 
			
		||||
    print(person['name'])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
url = 'http://api.open-notify.org/iss-now.json'
 | 
			
		||||
response = urllib.request.urlopen(url)
 | 
			
		||||
result = json.loads(response.read())
 | 
			
		||||
 | 
			
		||||
print(result)
 | 
			
		||||
 | 
			
		||||
location = result['iss_position']
 | 
			
		||||
latitude = location['latitude']
 | 
			
		||||
longitude = location['longitude']
 | 
			
		||||
 | 
			
		||||
print('Latitude:  ',latitude)
 | 
			
		||||
print('Longitude: ',longitude)
 | 
			
		||||
 | 
			
		||||
screen = turtle.Screen()
 | 
			
		||||
 | 
			
		||||
screen.setup(720,360)
 | 
			
		||||
screen.setworldcoordinates(-180,-90,180,90)
 | 
			
		||||
screen.bgpic('map.gif')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
screen.register_shape('iss.gif')
 | 
			
		||||
iss = turtle.Turtle()
 | 
			
		||||
iss.shape('iss.gif')
 | 
			
		||||
iss.setheading(90)
 | 
			
		||||
 | 
			
		||||
iss.penup()
 | 
			
		||||
iss.goto(float(longitude),float(latitude) )
 | 
			
		||||
 | 
			
		||||
# Print the map
 | 
			
		||||
 | 
			
		||||
time.sleep(10)
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								bigos/lecture20250415/urllib/iss/iss-project-resources.zip
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bigos/lecture20250415/urllib/iss/iss-project-resources.zip
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										10415
									
								
								bigos/lecture20250415/urllib/iss/result.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10415
									
								
								bigos/lecture20250415/urllib/iss/result.html
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue