4

I'm trying to include a legend in an Incanter chart, but I'm having some troubles getting what I want:

  1. I want to be able to instantiate a chart with no data first (using [] [] as my x y arguments), then add the data points in a separate step. However the only way to add a legend is to specify :legend true after the initial x y points are given in the constructor. Cannot specify :legend true without x y arguments, and I have not found any add-legend function.

  2. The legend option captures the code I use when adding the chart data, which means if I don't want ugly code to appear in the legend I have to create a nice-looking vars for the X and Y points, rather than just calling a function in line.

  3. Therefore the legend that is created includes the [][] used when creating the blank plot, it includes the function calls used when getting the data for the points, and it includes the name-mangled anonymous function (fn*[p1__3813#](second p1__3813#)) which is non-communicative to consumers of my chart.

  4. I just want to be able to associate a string with each group of points in the legend like in matlab, excel, etc.

Here is my current code;

(def lux-ratios-plot
   (doto (scatter-plot [] [] :legend true
                             :title  "Lux/CH0 vs. CH1/CH0"
                             :x-label "CH1/CH0"
                             :y-label "Lux/CH0")
     (view)))

(doseq [dut [incs hals cfls leds]]
  (add-points lux-ratios-plot (get-vals :CH1/CH0 dut) (get-vals :Lux/CH0 dut) :points true))

; Show the trend line for each bulb
(doseq [fit [inc-fit hal-fit cfl-fit led-fit]]
  (add-lines lux-ratios-plot (map #(second %) (:x fit)) (:fitted fit)))

Therefore is there any way in Incanter plots to specify a legend string with each (add-lines ...) or (add-points ...) call?

Thanks a lot

Michael

4

2 に答える 2

2

すべての Incanter チャートは、JFreeChart オブジェクトでもあります。したがって、任意の JFreeChart メソッドを使用して Incanter チャートを操作できます。

たとえば、凡例を削除するには (.removeLegend lux-ratios-plot) を実行できます。addLegendメソッドもあります。それを自分で試したことはありません。お役に立てれば。

于 2012-02-25T22:39:10.483 に答える
0

一連のポイントまたはラインにナイス ネームを関連付けるに:series-labelは、そのデータをチャートに追加するコマンドでキーワードを使用します。例えば:

(def c (scatter plot x y :legend true))
(add-lines c x1 y1 :series-label "Primary")
(add-lines c x2 y2 :series-label "Secondary")

これは、質問の他の問題には対処しません。凡例を持つ裸の散布図を作成するには、空のデータを に渡すscatter-plot必要xyあります。:legendにデータを渡さずにscatter-plotxyが空の場合(たとえばnil)、空のデータも凡例の要素として表示されます。現在、この問題を直接解決できるとは思えません (バージョン 1.5.7)。

:series-label1 つの解決策は、パラメーターと共に散布図呼び出しで実際のデータを渡すことです。ただし、最初のデータセットを他のデータセットとは異なる方法で処理する必要があるため、事前にデータセットの数が不明な場合、プログラムで散布図を生成するのが面倒になる場合があります。

別の、面倒な解決策は次のとおりです。

(def chart (scatter-plot nil nil :legend true :series-label ""))
(set-stroke-color chart (java.awt.Color. 0 0 0 0) :dataset 0)

の値として空の文字列を使用する:series-labelと、最初の空のデータセットの凡例のラベルが表示されなくなります。このset-stroke-color呼び出しにより、空のデータセット (つまり、データセット 0) の色が透明になります。それ以外の場合は、凡例にこのデータセットの赤い点が表示されます。凡例には、赤い点と空の文字列が属する小さな空白がありますが、そこに赤い点が表示されるよりも混乱しません。

于 2016-09-24T18:13:08.557 に答える