cchalmers / plots

Haskell plotting library
BSD 3-Clause "New" or "Revised" License
44 stars 10 forks source link

y-axis extends beyond zero with no points below zero. #34

Open GregorySchwartz opened 7 years ago

GregorySchwartz commented 7 years ago

In the line plot example: if I just add one point at the y-axis of 0 (mydata3 point 2), no data point goes below 0 yet the y-axis extends beyond 0 and looks unpleasant. I would expect this plot's axis to begin at 0 for both the x- and y-axis. However, I do not recommend cutting it at the lowest or highest datapoint automatically at all, I think it should be a special case for 0 in the x- and y-axis.

{-# LANGUAGE FlexibleContexts #-}

import Plots
import Diagrams.Prelude
import Plots.Axis.Line

import Data.Typeable

mydata1 = [(1,3), (2,5.5), (3.2, 6), (3.5, 6.1)]
mydata2 = mydata1 & each . _1 *~ 0.5
mydata3 = [V2 1.2 2.7, V2 1.7 0, V2 2 5.1, V2 3.2 2.6, V2 3.5 5]

myaxis :: Axis B V2 Double
myaxis = r2Axis &~ do
  linePlot' mydata1
  linePlot mydata2 $ do
    key "data 2"
    plotColor .= black

  linePlot mydata3 $ key "data 3"

  hideGridLines
  xAxis . axisLineType .= MiddleAxisLine
  yAxis . axisLineType .= LeftAxisLine

  lineStyle . _lineCap .= LineCapSquare
  lineStyle . _lineJoin .= LineJoinBevel

dia = renderAxis myaxis
cchalmers commented 7 years ago

This is interesting suggestion. I'm not happy with the current way the bounds and ticks etc. are done done currently and I want to have an overhaul. When I do I'll consider this. (It will be a while until I get round to doing it)