0
我试图在图上绘制形状。这里是我的代码...Matplotlib绘制图形上的形状
def graphData(self, stock):
stock_file = Company.objects.get(ticker_name=stock)
stock_file = stock_file.data
stock_file = stock_file.replace("[","").replace("]","").replace("'","")
stock_file = re.sub("(([^,]*,){5}[^,]*),\s*","\\1\n",stock_file)
file_name = "/home/philip/PycharmProjects/stockmarket/static/stock_data/data_file.txt"
file = open(file_name, "w")
points = [[2, 4], [2, 8], [4, 6], [6, 8]]
line = plt.Polygon(points, closed=None, fill=None, edgecolor='r')
file.write(stock_file)
file.close()
date, closep, highp, lowp, openp, volume = np.loadtxt(file_name, delimiter=",", unpack=True, converters={ 0: date_converter })
fig = plt.figure()
ax1 = plt.subplot(1,1,1)
ax1.plot(date, openp)
ax1.plot(date, highp)
ax1.plot(date, lowp)
ax1.plot(date, closep)
ax1.grid(True)
ax1.xaxis.set_major_locator(mticker.MaxNLocator(10))
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m-%Y'))
for label in ax1.xaxis.get_ticklabels():
label.set_rotation(90)
plt.subplots_adjust(left=.10, bottom=.22, right=.93, top=.95)
plt.xlabel('Date')
plt.ylabel('Stock Price')
plt.suptitle(stock+': Stock Price')
plt.show()
plt.savefig("/home/philip/PycharmProjects/stockmarket/static/graph.svg")
开始points = ...
和line = ...
的两条独立的线路被我加入到尝试绘制形状的代码。为什么这不起作用?
嗯。依然不起作用。你可以尝试用我的代码来验证它的系统错误吗? –
好吧我现在已经把它绘制出来了,但它绘制了它而不是我的其他数据而不是它。 –
“点”坐标和“日期”和股票价格之间的关系是什么?例如,如果'日期'的范围从'2000-1-1'到'2016-1-1',那么''(2,4)'点位于图表的哪个位置? – unutbu