Posts

Showing posts from August, 2020

python -matplotlib

Image
from matplotlib import pyplot as plt from matplotlib import style style.use( 'ggplot' ) #設定背景 x = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] y = [ 18 , 21 , 4 , 3 , 45 , 17 , 16 , 5 , 6 ] x2 = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] y2 = [ 17 , 28 , 14 , 16 , 15 , 13 , 1 , 5 , 6 ] plt.subplot( 211 ) #有2個圖表,第1個顯示在第1位 plt.plot(x , y , linewidth = 3 , marker = 'o' , label = 'truthValue' ) plt.plot(x2 , y2 , color = 'y' , label = 'prediction' ) plt.legend() plt.subplot( 212 ) #有2個圖表,第1個顯示在第2位 plt.bar(x , y , align = 'center' , label = 'truthValue' ) plt.bar(x2 , y2 , align = 'center' , label = 'prediction' ) #marker轉折點符號 plt.legend() plt.ylabel( 'price' ) plt.xlabel( 'date' ) plt.show()

Python install

Image
☝python upgrade 1.brew upgrade python 2.echo "alias python=/usr/local/bin/python3.8" >> ~/.zshrc 版本太多, 以為打python3 -m 就可以解決一切,但還是 有抓前版本的 package , so最好將python全刪,再重新安裝: /usr/local/bin/下的 全部的python /Library/Python /Library/Frameworks/Python.framework ☝  pip 套件管理員 curl https : // bootstrap . pypa . io / get - pip . py - o get - pip . py python get - pip . py ☝venv環境工作管理員 ☝ conda 安裝  = pip + venv 在安裝時我自選習慣儲存的位置:/usr/local package安裝 ☝matplotlib //可產生多種不同繪圖類型,  嵌入繪圖, 其數值數學(數據分析)擴展包  NumPy 的可視化操作界面 ☝mpl_finance ☝numpy ☝pandas //python 的 Excel;pandas-datareader用來獲取資料 ☝pandas-datareader ☝yfinance yahoo股市資料 # import yfinance as yf

Dart syntax - initSate,Build,deactive, Dispose

 ☝ initSate(){ super.initSate   //放置一旦載入statefulwidget後就不需一直更新的物件。 } 如字面的意思in it sate. 此功能好比statefulwidget 裡面的statelesswidget。   Called only once when the widget is created,只會執行一次,不像build() 一變動就自毀後重建。 ☝Build(BuildContext context) { //放置載入後每次有任何變動就需更新的物件。 }          - Build the widget tree         -A build is triggred every time we use setState() that re-triggre build(). ☝ deactive() {super.deactive // 放置當statefulwight自毀換頁前跟著毀的物件。例如:釋放記憶空間。 } ☝Dispose()          - When the widget/state object is removed.

flutter-QuoteCard

Image
  import 'package:flutter/material.dart' ; void main () { runApp( MaterialApp ( debugShowCheckedModeBanner: false, home: quote () , )) ; } class quote extends StatefulWidget { @override _quoteState createState () => _quoteState () ; } class _quoteState extends State<quote> { List<Quote> quotes = [ Quote (text: 'Be yourself; everyone else is already taken.' , author: ' Oscar Wilde' ) , Quote (text: 'So many books, so little time.' , author: 'Frank Zappa' ) , Quote (text: 'A room without books is like a body without a soul.' , author: 'Marcus Tullius Cicero' ) , ] ; @override Widget build (BuildContext context) { return Scaffold ( backgroundColor: Colors. grey [ 100 ] , appBar: AppBar ( title: Text ( 'Awesome Quote Card' , style: TextStyle ( color: Colors. grey [ 100 ] , fontSize: 20 , )

flutter-ID Card -statefulwidget

Image
Statefulwidget 用setState((){ })方法變更元件。 import 'package:flutter/material.dart' ; void main () { runApp( MaterialApp ( debugShowCheckedModeBanner: false , home: snoopyCard () , )) ; } class snoopyCard extends StatefulWidget { @override _snoopyCardState createState () => _snoopyCardState () ; } class _snoopyCardState extends State<snoopyCard> { int level = 0 ; @override Widget build (BuildContext context) { return Scaffold ( backgroundColor: Colors. grey [ 900 ] , appBar: AppBar ( title: Text ( 'Snoopy ID Card' , style: TextStyle ( color: Colors. grey [ 400 ] , fontSize: 20 , ) , ) , centerTitle: true, backgroundColor: Colors. grey [ 850 ] , ) , body: Padding ( padding: EdgeInsets . fromLTRB ( 30 , 40 , 30 , 0 ) , child: Column ( crossAxisAlignment: CrossAxisAlignment. start , children: [ Center (

Flutter -ID Card- Statelessweight

Image
Learn From:The Net Ninja   import 'package:flutter/material.dart' ; void main () { runApp( MaterialApp ( debugShowCheckedModeBanner: false , home: snoopyCard () , )) ; } class snoopyCard extends StatelessWidget { @override Widget build (BuildContext context) { return Scaffold ( backgroundColor: Colors. grey [ 900 ] , appBar: AppBar ( title: Text ( 'Snoopy ID Card' , style: TextStyle ( color: Colors. grey [ 400 ] , fontSize: 20 , ) , ) , centerTitle: true, backgroundColor: Colors. grey [ 850 ] , ) , body: Padding ( padding: EdgeInsets . fromLTRB ( 30 , 40 , 30 , 0 ) , child: Column ( crossAxisAlignment: CrossAxisAlignment. start , children: [ Center ( child: CircleAvatar ( backgroundImage: AssetImage ( 'assets/snoopy.jpg' ) , radius: 40 , ) ,

Flutter - stateless vs stateful

Image
Hot reload: 自動更新。(儲存後自動reload) ☝stateless widgets :the state of the widget cannot change over time.  快速鍵stless  ☝stateful widgets: the state of the widget can change over time.  If a widget can change—when a user interacts with it. 與使用者互動時,部件能有所變化。 反之,則使用stateless即使。 ☝Row()

Android Studio Hotkey

Image
☝command + / 將前面的# 字號刪除 ☝shift + Tab 縮進(unindent code) ☝Control J //quick document

Dart syntax - Isolates,typedefs,metadata@

Image
☝ called  讓實體能像方法一樣 ☝ Isolates dart能讓每個isolates有自己的記憶體和單線,解決多項事件同時共享記憶體時容易發生錯誤的問題。 ☝ typedefs  很像填表單一樣,有個單表名稱,內容就是自定義一個制式的程式格式。初始即對應填表單。 ☝metadata @程式注記。可自定義。建立dart ,後導入 import xxx.dart ,@xxx。

Dart syntax - get,set,abstract,implicit,@,enum,mixin,mixin on

Image
 ☝runtimeType 回傳該物件的型別。 ☝get set 提供讀取寫入物件屬性功能,讓你可以用. 去建立其附加屬性。 ☝抽象類別,不能成為實體物件,常用於定義介面執行上。必須由子類別來實作或擴充功能。 ☝implicit interfaces 隱式介面。不需要A的全部,只想用A某功能。 ☝@override 注釋為覆寫,並驗証父類別是否有該方法名,如果沒有則出現error. ☝enum 列舉enumerated 一個enum都有排列index ☝mixin 可用mixin取代class即可, 除非你想要你的mixin能像普通的class。也就是說內部自用。 ☝mixin on 僅供指定類別使用。

Dart syntax- if else for, forEach,throw, try catch,try on

Image
 ☝if  else 可多條件 ☝for 單條件 ☝for ☝forEach ☝forEach = for-in 一一叫出來 👉自訂例外(exception / error)處理 throw & try catch & try on ☝try catch  無指定型別 ☝try on  type  指定型別 ☝try catch  final  final是用於確認某特定的code是否有例外丟出。 ☝try{...}catch(e){...  rethrow };  可看到系統定義的例外訊息。

Dart syntax - operators

Image
☝ + - * / ~/ % ☝++ -- ☝*= ☝is 與 as ☝? :  = if else  ☝?? 第一個? 是判斷是否為null, 第2個 ? 是if運算子,如果是null就執行 ☝??= 判斷如果值為null,再給值,要不然就照舊。 ☝.. 很像this. 用呼叫其物件,第一個.表物件本身;而第二個,指向其屬性/變數/方法。 phone.number 等於 phone() ..number ☝?. 第一個?表其物件value允許為null,以避免例外發生;而第二個,指向其屬性/變數/方法。 phone?.number //可允許phone沒有值。

Dart - Function

Image
☝ =>    相當於 { return ...}用於 F unction 只有一行程式碼 var myFunction= myFunction(x){ return x+1}; var myFunciton = (x) => x +1;  int myFunction(x) => x + 1; * => 只有運算式(由運算元及運算子組成)可以用,而statement陳述語法是不可以的哦! ☝ 匿名函數(又稱Closure): 將一行程式當成變數或參數。 ☝ 命名參數 有名字,呼叫時得先輸入名字: 然後值。易讀性高。 呼叫參數時: myFunction(param1 : Value ); 定義參數時 myFunction( { type  param1, type param2 ... } ) {...} ☝參數前置入 @required,表示為 強制性的參數,使用時必須給值。 像是Scrollbar如果參數沒有指定child就會出現錯誤: const Scrollbar({Key key, @required Widget child}) ; ☝Positinal 參數。使用方法時不需先輸入參數名,就對號入座。這個方法比較不易辨讀。 String myFunction (type param1, type param2, [ type param3]) {...} myFunction(value1, value2, value3); ☝top-level :程式進入點。如main() ☝lexical scope   一函數裡的函數/變數,內層不被外層使用,外層可被內層使用。 好比主管(外層),員工(內層);員工不可跨部門,而主管可以。 ☝lexical closure 是函數物件。其它函數呼叫使用能夠存取參數所植入的值。 ☝物件 比較  : 第一個建立類別物件與第二個建立類別為不同的實體物件。 ☝ 沒給值,預設return都會是null

Flutter - packages install example

Image
以 charcaters 為例,下載檔案後, 將檔案裡面的 pubspec.yaml  移到自己的專案,開啟後,更改專案名(我的是dart),於下方貼上: dependencies: characters: ^1.0.0 //注意階級,為dependencies的下一層 儲存,VS code會自動執行pub get,如果沒自動就可自行在TERMINAL pub get , 如果是flutter 就 flutter pub get. 如此一來 import 'package:characters/characters.dart' ; 就可以使用了。

Dart syntax - ${},r,List,Map, ... & ...?

Image
☝${ expression } ☝raw ☝list 也就是所謂的array ☝... 與  ...?  之插入功能 spread operator  ( ... ) and the  null-aware spread operator  ( ...? ), which provide a concise way to insert multiple elements into a collection. ☝list 之for / if之應用 ☝Map 字典-有索引值的陣列