pythonmatplotlib

matplotlib won't plot line of same x values


I'm having some trouble getting matplotlib to plot a graph if my Y values are all the same.

I am plotting a graph of temperature against time, and I have found that if my temperatures are all the same I get no line plotted, as soon as a temperature change is added to the plot, the line is then drawn.

I have been able to force it to draw the line always by initialising my list of temperatures with a value of zero (0), but that only works assuming the temperature isn't at zero for any time.

Is there a way I can cause it to plot my graph properly without priming with fake values?

Fields:

    temperature = []
    time = []
    minY = 0
    maxY = 0

Setting (on sensor poll):

    temp = float(params['temp'][0])
    time = datetime.now()
    self.temperature.append(temp)
    self.time.append(time)

Plot:

    plt.figure()
    plt.xlabel("Time")
    plt.ylabel("Temperature (Celcius)")
    plt.title("Temperature in ...")
    plt.ylim(self.minY,self.maxY)
    plt.plot(self.time,self.temperature, "c")
    plt.gcf().autofmt_xdate()
    plt.savefig("temp.svg")

Edit: If I set plot type to "o" (circles) when I call plot, I can see the circles on the same line, if I switch back to the default line type, I see nothing.

Edit2: Switching output format to png produces the line correctly. Why is SVG not doing so?


Solution

  • As it turns out (after I inspected the content of the SVG file) there is nothing wrong with the code or with matplotlib, it turns out that Google Chrome refuses to display the straight line in the SVG.

    I tried the output in Illustrator and Internet Explorer and it works fine.