2018年8月30日 星期四

[Python Package] matplotlib使用記錄

前言:
資料視覺化是了解資料與報告成果的重要方式,在Python常用matplotlib套件來畫圖,
以下紀錄使用的語法。


語法:

在jupyter notebook常用,宣告後,不用每次寫plt.show()。

matplotlib可自訂繪圖風格,ggplot風格就是模仿R的知名繪圖套件ggplot2,讓繪圖更美觀。

一般二維的折線圖,使用plot函式,簽章如下:

[]代表optional,fmt表format字串,可用來決定折線顏色、資料點標記與折線樣式。

例:'yo-'表line為黃色、資料點圓形、line粗體。


plot函式使用,例:
plt.plot([0,1,2], [0,10,0])
plt.plot([0,1,2], [0,10,0], 'g.-')


to be continued...


參考資料:
https://matplotlib.org/gallery/style_sheets/ggplot.html#sphx-glr-download-gallery-style-sheets-ggplot-py
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html


2018年8月22日 星期三

[.Net MVC] Items could not be selected(null) in Multiple Select(ListBox)

前言:
網頁中常用Multi Select或稱ListBox供使用者多選Items,如:
<select multiple>
<option value="Taiwan">Taiwan</option>
<option value="USA">USA</option>
</select>
 或
@Html.ListBox("country", null, new {multiple = multiple})

當option items render後,又沒有被點選,會發生回傳item為null的狀況,
該如何處理?


作法:
● 在form post前,將option加上selected的屬性。
$('form').submit(function(){
   $('#target option').attr("selected", "selected");
});
若上述做法行不通,可使用下面方法:
● append option value到某一hidden element,再post到後端。



參考資料: