path('plot/', views.plot.as_view(), name='plot'), # 单股可视化
时间: 2023-06-27 21:07:01 浏览: 48
这是一个 Django 中的 urlpattern,它将请求路径为 "plot/" 的 GET 请求映射到名为 "plot" 的视图函数上。这个视图函数的实现由 views.py 文件中的 plot 类视图提供。它用于呈现单个股票的可视化图表。当用户在浏览器中输入 URL "http://yourwebsite.com/plot/" 时,Django 将调用 plot 视图函数,并将其渲染到用户的浏览器中。
相关问题
self.plot_canvas.update_xaxes(matches='x')
`self.plot_canvas.update_xaxes(matches='x')` 是用于更新 matplotlib 中的绘图区域 `self.plot_canvas` 上 x 轴的方法。其中,`matches='x'` 表示将所有的 x 轴上的属性都设置为相同的值。
在 matplotlib 中,我们可以使用 `update_xaxes()` 和 `update_yaxes()` 等方法来更新绘图区域上的坐标轴属性。这些方法可以接受很多参数,并且可以一次性设置多个属性,例如:
```python
import matplotlib.pyplot as plt
# 创建 Figure 对象和 Axes 对象
fig, ax = plt.subplots()
# 在 Axes 对象中绘制图表
ax.plot([1, 2, 3], [4, 5, 6], label='Line 1')
# 设置绘图区域的标题和标签
ax.set_title('My Plot')
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
# 更新 x 轴的属性
ax.update_xaxes(title='X Axis', showgrid=True)
# 显示图例
ax.legend()
# 显示图表
plt.show()
```
在上面的例子中,`ax.update_xaxes()` 方法被用于更新 x 轴的属性,包括标题和网格线。具体来说,`ax.update_xaxes(title='X Axis', showgrid=True)` 表示将 x 轴的标题设置为 'X Axis',并显示网格线。这样,在显示图表时,就可以看到更新后的 x 轴属性。
总之,`self.plot_canvas.update_xaxes(matches='x')` 也是类似的更新 x 轴属性的方法,它可以将绘图区域上所有的 x 轴属性都设置为相同的值。
n_classes = 3 n_estimators = 30 plot_colors = "ryb" cmap = plt.cm.RdYlBu plot_step = 0.02 # fine step width for decision surface contours plot_step_coarser = 0.5 # step widths for coarse classifier guesses RANDOM_SEED = 13 # fix the seed on each iteration iris = load_iris() plot_idx = 1 models = [DecisionTreeClassifier(max_depth=None), RandomForestClassifier(n_estimators=n_estimators), ExtraTreesClassifier(n_estimators=n_estimators), AdaBoostClassifier(DecisionTreeClassifier(max_depth=3), 将上面的代码加上注释
下面是对该代码的注释:
```python
# 导入需要的库和模块
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, ExtraTreesClassifier, AdaBoostClassifier
import matplotlib.pyplot as plt
import numpy as np
# 定义需要的参数
n_classes = 3 # 类别数
n_estimators = 30 # 集成模型中基分类器的数量
plot_colors = "ryb" # 绘图时使用的颜色
cmap = plt.cm.RdYlBu # 绘图时使用的颜色映射
plot_step = 0.02 # 决策面轮廓线的细度
plot_step_coarser = 0.5 # 粗略分类器猜测的步骤宽度
RANDOM_SEED = 13 # 每次迭代时固定种子
# 加载鸢尾花数据集
iris = load_iris()
# 设置绘图的子图位置
plot_idx = 1
# 定义四个基分类器
models = [DecisionTreeClassifier(max_depth=None), # 决策树
RandomForestClassifier(n_estimators=n_estimators), # 随机森林
ExtraTreesClassifier(n_estimators=n_estimators), # 极端随机树
AdaBoostClassifier(DecisionTreeClassifier(max_depth=3), # AdaBoost
n_estimators=n_estimators)]
# 开始绘制四个基分类器的决策面
for pair in ([0, 1], [0, 2], [2, 3]):
for model in models:
# 从数据集中选取两个特征作为x轴和y轴
X = iris.data[:, pair]
y = iris.target
# 随机化样本,将数据集分成训练集和测试集
idx = np.arange(X.shape[0])
np.random.seed(RANDOM_SEED)
np.random.shuffle(idx)
X = X[idx]
y = y[idx]
half = int(X.shape[0] / 2)
X_train, X_test = X[:half], X[half:]
y_train, y_test = y[:half], y[half:]
# 训练基分类器
model.fit(X_train, y_train)
# 绘制训练集和测试集的散点图
plt.subplot(3, 4, plot_idx)
plt.tight_layout()
plt.scatter(X_train[:, 0], X_train[:, 1], c=y_train, cmap=cmap, edgecolor='k')
plt.scatter(X_test[:, 0], X_test[:, 1], c=y_test, cmap=cmap, alpha=0.6, edgecolor='k')
# 绘制决策面轮廓线
xx, yy = np.meshgrid(np.arange(X[:, 0].min() - 1, X[:, 0].max() + 1, plot_step),
np.arange(X[:, 1].min() - 1, X[:, 1].max() + 1, plot_step))
Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
cs = plt.contourf(xx, yy, Z, cmap=cmap, alpha=.5)
# 绘制分类器猜测的决策面轮廓线
xx_coarser, yy_coarser = np.meshgrid(np.arange(X[:, 0].min() - 1, X[:, 0].max() + 1, plot_step_coarser),
np.arange(X[:, 1].min() - 1, X[:, 1].max() + 1, plot_step_coarser))
Z_points_coarser = model.predict(np.c_[xx_coarser.ravel(), yy_coarser.ravel()]).reshape(xx_coarser.shape)
cs_points = plt.scatter(xx_coarser, yy_coarser, s=15, c=Z_points_coarser, cmap=cmap, edgecolor='none')
# 设置图像的标题和绘图的标签
plt.title(pair)
plot_idx += 1
# 显示绘制结果
plt.suptitle("Classifiers on feature subsets of the Iris dataset")
plt.axis("tight")
plt.show()
```
相关推荐
股票可见
股票可视化和比较
添加多个股票并在图表上可视化比较
技术栈
短跑
密谋
熊猫数据读取器
设置
使用Api键将环境变量“ ALPHAVAN”设置为“值”,或者您可以在conf中更改API名称并在“环境”中设置该值。
pip install -r requirements.txt
对于本地运行: : :
在您自己的Heroku上设置
在server.py (deployment = app.server)中包含(Remove-#)第12行
包括(Remove-#) (gunicorn)在requirement.txt
请遵循以下命令:
heroku创建
git添加
git commit -m“首次部署”
git push heroku主
如果使用免费heroku ps:scale web=1这些是实验性的
部署将在url上: https