From c62e8a8a898f1229f6b93a52ede6b28e9d41c959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 2 Mar 2025 05:23:19 +0100 Subject: [PATCH] Image, Plotly, Cython --- README.md | 14 +++++++------- index.html | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e646a6c..8614d7b 100644 --- a/README.md +++ b/README.md @@ -2828,11 +2828,11 @@ img.show() from PIL import ImageDraw = ImageDraw.Draw() # Object for adding 2D graphics to the image. .point((x, y)) # Draws a point. Truncates floats into ints. -.line((x1, y1, x2, y2 [, ...])) # To get anti-aliasing use Image's resize(). +.line((x1, y1, x2, y2 [, ...])) # For anti-aliasing use .resize((w, h)). .arc((x1, y1, x2, y2), deg1, deg2) # Draws in clockwise dir. Also pieslice(). .rectangle((x1, y1, x2, y2)) # Also rounded_rectangle(), regular_polygon(). -.polygon((x1, y1, x2, y2, ...)) # Last point gets connected to the first. -.ellipse((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste(). +.polygon((x1, y1, x2, y2, ...)) # Last point gets connected to the first one. +.ellipse((x1, y1, x2, y2)) # To rotate use .rotate(anticlock_deg). .text((x, y), , font=) # ` = ImageFont.truetype(, size)`. ``` * **Use `'fill='` to set the primary color.** @@ -3457,7 +3457,7 @@ px.line(df, x='Date', y='Total Deaths per Million', color='Continent').show() ```python # $ pip3 install pandas lxml selenium plotly -import pandas as pd, selenium.webdriver, plotly.graph_objects as go +import pandas as pd, selenium.webdriver, io, plotly.graph_objects as go def main(): covid, (bitcoin, gold, dow) = get_covid_cases(), get_tickers() @@ -3466,7 +3466,7 @@ def main(): def get_covid_cases(): url = 'https://covid.ourworldindata.org/data/owid-covid-data.csv' - df = pd.read_csv(url, usecols=['location', 'date', 'total_cases'], parse_dates=['date']) + df = pd.read_csv(url, parse_dates=['date']) df = df[df.location == 'World'] s = df.set_index('date').total_cases return s.rename('Total Cases') @@ -3482,7 +3482,7 @@ def get_ticker(driver, name, symbol): driver.get(url + '?period1=1579651200&period2=9999999999') if buttons := driver.find_elements('xpath', '//button[@name="reject"]'): buttons[0].click() - dataframes = pd.read_html(driver.page_source, parse_dates=['Date']) + dataframes = pd.read_html(io.StringIO(driver.page_source), parse_dates=['Date']) s = dataframes[0].set_index('Date').Open return s.rename(name) @@ -3529,7 +3529,7 @@ import # Script must be saved with '.pyx' extens #### Definitions: * **All `'cdef'` definitions are optional, but they contribute to the speed-up.** -* **Also supports C pointers via `'*'` and `'&'`, structs, unions, and enums.** +* **Also supports C pointers (via `'*'` and `'&'`), structs, unions and enums.** ```python cdef [= ] diff --git a/index.html b/index.html index 75c7b34..3dac48a 100644 --- a/index.html +++ b/index.html @@ -56,7 +56,7 @@
- +
@@ -2313,11 +2313,11 @@ img.show()

Image Draw

from PIL import ImageDraw
 <Draw> = ImageDraw.Draw(<Image>)                # Object for adding 2D graphics to the image.
 <Draw>.point((x, y))                            # Draws a point. Truncates floats into ints.
-<Draw>.line((x1, y1, x2, y2 [, ...]))           # To get anti-aliasing use Image's resize().
+<Draw>.line((x1, y1, x2, y2 [, ...]))           # For anti-aliasing use <Image>.resize((w, h)).
 <Draw>.arc((x1, y1, x2, y2), deg1, deg2)        # Draws in clockwise dir. Also pieslice().
 <Draw>.rectangle((x1, y1, x2, y2))              # Also rounded_rectangle(), regular_polygon().
-<Draw>.polygon((x1, y1, x2, y2, ...))           # Last point gets connected to the first.
-<Draw>.ellipse((x1, y1, x2, y2))                # To rotate use Image's rotate() and paste().
+<Draw>.polygon((x1, y1, x2, y2, ...))           # Last point gets connected to the first one.
+<Draw>.ellipse((x1, y1, x2, y2))                # To rotate use <Image>.rotate(anticlock_deg).
 <Draw>.text((x, y), <str>, font=<Font>)         # `<Font> = ImageFont.truetype(<path>, size)`.
 
@@ -2816,7 +2816,7 @@ px.line(df, x='Date', y=Displays a multi-axis line chart of total coronavirus cases and changes in prices of Bitcoin, Dow Jones and gold:

# $ pip3 install pandas lxml selenium plotly
-import pandas as pd, selenium.webdriver, plotly.graph_objects as go
+import pandas as pd, selenium.webdriver, io, plotly.graph_objects as go
 
 def main():
     covid, (bitcoin, gold, dow) = get_covid_cases(), get_tickers()
@@ -2825,7 +2825,7 @@ px.line(df, x='Date', y=def get_covid_cases():
     url = 'https://covid.ourworldindata.org/data/owid-covid-data.csv'
-    df = pd.read_csv(url, usecols=['location', 'date', 'total_cases'], parse_dates=['date'])
+    df = pd.read_csv(url, parse_dates=['date'])
     df = df[df.location == 'World']
     s = df.set_index('date').total_cases
     return s.rename('Total Cases')
@@ -2841,7 +2841,7 @@ px.line(df, x='Date', y='?period1=1579651200&period2=9999999999')
     if buttons := driver.find_elements('xpath', '//button[@name="reject"]'):
         buttons[0].click()
-    dataframes = pd.read_html(driver.page_source, parse_dates=['Date'])
+    dataframes = pd.read_html(io.StringIO(driver.page_source), parse_dates=['Date'])
     s = dataframes[0].set_index('Date').Open
     return s.rename(name)
 
@@ -2885,7 +2885,7 @@ px.line(df, x='Date', y=Definitions:
  • All 'cdef' definitions are optional, but they contribute to the speed-up.
  • -
  • Also supports C pointers via '*' and '&', structs, unions, and enums.
  • +
  • Also supports C pointers (via '*' and '&'), structs, unions and enums.
cdef <ctype/type> <var_name> [= <obj>]
 cdef <ctype>[n_elements] <var_name> [= <coll_of_nums>]
 cdef <ctype/type/void> <func_name>(<ctype/type> <arg_name>): ...
@@ -2942,7 +2942,7 @@ $ deactivate                # Deactivates the active