Matplotlib只显示点 - 不是线

时间:2015-01-08 04:19:56

标签: python python-2.7 matplotlib

我的matplotlib图表没有显示实线。它只显示实际点。我甚至指定了线宽。无法弄清楚它为什么没有出现。

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
import numpy as np
import matplotlib.dates as mdates

fig = plt.figure()
ax = fig.add_subplot(111)

graphArray = []
MyData = open("SampleText.txt","r").read()
Split_by_line = MyData.split('\n')

for item in Split_by_line:
    splitInfo = item.split(',')

    graphArrayAppend = splitInfo[0]+','+splitInfo[1]
    graphArray.append(graphArrayAppend)
datestamp, value= np.loadtxt(graphArray,delimiter=',', unpack=True,
                             converters={ 0: mdates.strpdate2num('%Y-%m-%d')})

ax.plot_date(x=datestamp, y=value, linewidth=2)

plt.show()

SampleText.csv

2014-01-01,6
2014-01-02,9
2014-01-03,4
2014-01-04,7
2014-01-05,7
2014-01-06,4
2014-01-07,4

1 个答案:

答案 0 :(得分:1)

绘图点的fmt(格式)参数的默认值为'o'。将其替换为-以绘制一条线:

ax.plot_date(x=datestamp, y=value, fmt='-', linewidth=2)