看板 Mathematica 關於我們 聯絡資訊
Mathematica 裡面繪製圖例的函數PlotLegend雖然功能將多, 但我個人覺得不是很好用,所以寫了一個比較陽春的函數。 如果有什麼其他的建議可以跟我講~ mylegend[plot_Graphics, legend_List] := Block[{p = plot, l = legend, color, temp}, (* 擷取色彩 *) color = Cases[p, Hue[a_, b_, c_] :> Hue[a, b, c], Infinity]; (* 配對圖例及色彩 *) temp = {color[[#]], l[[#]]} & /@ Range[Length@color]; (* 建立圖例 *) Labeled[p, Grid[{Graphics[{#[[1]], Thickness[0.1], Line[{{0, 0}, {1, 0}}]}, ImageSize -> {24, 24}, AspectRatio -> 8/24, ImagePadding -> 0], #[[2]]} & /@ temp], (* 指定圖例位置 *) {{Right, Top}}] ] 用法: mylegend[圖形,圖例文字] p1 = Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}] mylegend[p1,{Sin,Cos}] p2=ListLinePlot[Accumulate@RandomReal[{-1,1},100]&/@Range[5]] mylegend[p2,{"Series-1","Series-2","Series-3","Series-4","Series-5"}] p3=ContourPlot[Evaluate[x^2+y^2==#&/@Range[5]],{x,-3,3},{y,-3,3}] mylegend[p3,{"Circle-1","Circle-2","Circle-3","Circle-4","Circle-5"}] -- 養花種魚數月亮賞星星 http://chungyuandye.twbbs.org -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.173.130.220
Frobenius:推~ 07/05 15:33
xgcj:!! 07/05 16:39
kichigop:老師你發paper用的圖是直接Mathematica弄出來的嗎? 07/05 19:27
kichigop:還是用Origin或Grapher之類的軟體? 07/05 19:27
chungyuandye:我只有用Mathematica,轉成EPS也比較方便 07/05 20:18
Frobenius:請問怎麼用Mathematica轉成EPS?能互轉嗎^^ 07/05 23:30