- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想将以下数据分成两部分:observed
从 2018-09
到 2019-11
和 predicted
从 2019-12
到日期列的末尾,分别用 matplotlib
、plotly
或 用实线和虚线绘制它们>seaborn
等
date price pct
0 2018-09 10.599 0.020
1 2018-10 10.808 0.020
2 2018-11 10.418 -0.036
3 2018-12 10.166 -0.024
4 2019-01 9.995 -0.017
5 2019-02 10.663 0.067
6 2019-03 10.559 -0.010
7 2019-04 10.055 -0.048
8 2019-05 10.691 0.063
9 2019-06 10.766 0.007
10 2019-07 10.667 -0.009
11 2019-08 10.504 -0.015
12 2019-09 10.284 -0.021
13 2019-10 10.047 -0.023
14 2019-11 9.717 -0.033
15 2019-12 9.908 -0.029
16 2020-01 9.570 -0.045
17 2020-02 9.754 -0.023
18 2020-03 9.779 -0.025
19 2020-04 9.777 -0.031
20 2020-05 9.932 -0.020
我试过如下代码,首先我得到一个错误,其次我还没有绘制 pct
。有人可以帮忙吗?谢谢。
df = df.set_index('date')
plt.plot('date', 'price', data=df.loc['2018-09':'2019-11'], marker='o', color='green', linewidth=2)
plt.plot('date', 'price', data=df.loc['2019-12':], marker='o', color='green', linewidth=2, linestyle = '--')
它生成 ValueError: x 和 y must have same first dimension, but have shapes (1,) and (15,)
编辑:这段代码已经成功绘制了price
的图,但我需要在同一个图上绘制pct
。
df['date'] = pd.to_datetime(df['date'])
# https://stackoverflow.com/questions/46230864/split-dataframe-on-the-basis-of-date
split_date ='2019-12-01'
plt.figure(figsize=(10, 5))
plt.plot('date', 'rent_price', data = df.loc[df['date'] <= split_date], marker='o', color='red', linewidth=2)
plt.plot('date', 'rent_price', data = df.loc[df['date'] >= split_date], marker='o', color='green', linewidth=2, linestyle = '--')
最佳答案
我认为你所描述的最好用这样的 plotly 来说明:
完整代码:
# imports
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import pandas as pd
# your data
df = pd.DataFrame({'date': {0: '2018-09',
1: '2018-10',
2: '2018-11',
3: '2018-12',
4: '2019-01',
5: '2019-02',
6: '2019-03',
7: '2019-04',
8: '2019-05',
9: '2019-06',
10: '2019-07',
11: '2019-08',
12: '2019-09',
13: '2019-10',
14: '2019-11',
15: '2019-12',
16: '2020-01',
17: '2020-02',
18: '2020-03',
19: '2020-04',
20: '2020-05'},
'price': {0: 10.599,
1: 10.808,
2: 10.418,
3: 10.166,
4: 9.995,
5: 10.663,
6: 10.559000000000001,
7: 10.055,
8: 10.690999999999999,
9: 10.765999999999998,
10: 10.667,
11: 10.504000000000001,
12: 10.284,
13: 10.047,
14: 9.717,
15: 9.908,
16: 9.57,
17: 9.754,
18: 9.779,
19: 9.777000000000001,
20: 9.932},
'pct': {0: 0.02,
1: 0.02,
2: -0.036000000000000004,
3: -0.024,
4: -0.017,
5: 0.067,
6: -0.01,
7: -0.048,
8: 0.063,
9: 0.006999999999999999,
10: -0.009000000000000001,
11: -0.015,
12: -0.021,
13: -0.023,
14: -0.033,
15: -0.028999999999999998,
16: -0.045,
17: -0.023,
18: -0.025,
19: -0.031,
20: -0.02}})
# make timestamp to make plotting easier
df['timestamp']=pd.to_datetime(df['date'])
df=df.set_index('timestamp')
# split data
df_predict = df.loc['2019-11':]
df_actual = df[~df.isin(df_predict)].dropna()
# plotly setup
fig = make_subplots(rows=2,
cols=1,
subplot_titles=('Price', 'Pct'))
# Price, actual
fig.add_trace(go.Scatter(x=df_actual.index, y=df_actual['price'],
name = "price, actual",
mode='lines',
line=dict(color='steelblue', width=2)
)
,row=1, col=1)
# Price, prediction
fig.add_trace(go.Scatter(x=df_predict.index, y=df_predict['price'],
name = "price, prediction",
mode='lines',
line=dict(color='firebrick', width=2, dash='dash')
),
row=1, col=1)
# pct actual
fig.add_trace(go.Scatter(x=df_actual.index, y=df_actual['pct'],
mode='lines',
name = "pct, actual",
line=dict(color='steelblue', width=2)
)
,row=2, col=1)
# pct prediction
fig.add_trace(go.Scatter(x=df_predict.index, y=df_predict['pct'],
name="pct, prediction",
mode='lines',
line=dict(color='firebrick', width=2, dash='dash')
),
row=2, col=1)
fig.show()
关于python - 拆分数据并使用 Python 用实线和虚线绘制它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59187441/
最近,我在各种俄罗斯Web 2.0网站中看到了点缀和虚线超链接的广泛使用。通常,此类链接(在其下方具有虚线或虚线,而不是普通的实线)不会将用户引导至另一页面,而是在同一页面上执行操作而不重新加载该页面
Google 没有帮助我找到问题的解决方案。 (据我所知...)。 我想知道是否可以在 Android 上画一 strip 有 9 个补丁功能的虚线。 我的目标是从一个布局到另一个布局画一条虚线。 我
有没有办法将多条线段视为一条线? IE:我将鼠标悬停在一个上,两个都突出显示,切换图例中的可见性将隐藏两个部分。 http://jsfiddle.net/rayholland/HSvBj/2/ ser
我在我的 C# WinForms 应用程序中使用 .net 4.0 的图表控件。我有两个系列的数据显示为折线图。 我绘制的基本上是作为时间函数的供求关系图。我希望需求是某种颜色的实线,供应是相同颜色的
如何在窗口调整大小期间避免线划线调整大小?考虑下图: http://leprastuff.ru/data/img/20130315/b83eea4a7a3f07ca53a0e118ddbb9230.G
我正在尝试使用纯 webgl 创建虚线。我知道这已经有一个问题,也许我很笨,但我不知道如何让它发挥作用。我理解这个概念,但我不知道如何在着色器中获取沿路径的距离。以前的答案有以下行: varying
我们应该在序列图中的哪些步骤中使用返回线? )没有返回箭头,因为它们隐式返回实例化对象 编辑 2 针对您更新的问题: 我不会有用户操作的返回箭头,例如 login(),因为结果不会以与对象相同的方式
我正在尝试使用 gnuplot v4.4 绘制一个包含虚线和连续线的图形。代码是: set term postscript eps enhanced color set style line 1 li
我正在尝试创建一个 React nivo 折线图,其中包含虚线而不是实线。我研究过图案,但不知道如何制作图案。感谢您的帮助。 最佳答案 nivo 在库中提供了自定义图层功能,您可以使用它来自定义从实线
我正在尝试创建一个 React nivo 折线图,其中包含虚线而不是实线。我研究过图案,但不知道如何制作图案。感谢您的帮助。 最佳答案 nivo 在库中提供了自定义图层功能,您可以使用它来自定义从实线
我使用一些通过的点创建虚线 UIBezierPath。 let pathLayer = CAShapeLayer() pathLayer.strokeColor = UIColor.blue.cgCo
我有以下问题。我必须从很多距离太近的点画一个圆。您可以在下面的 jsfiddle 链接中看到它: http://jsfiddle.net/L6e5oz3L/
我是 CSS 的新手,正在网上寻找自动重新压缩图像的代码,我发现的代码可以完美地做到这一点。但正确的是,它重新调整图像周围的一些红色虚线,当我尝试编辑时,整个图像消失了。可以请有人帮我解决图像显示时如
已将 Firebase Analytics 集成到我的 Android 项目中,它上个月运行正常,现在它只显示虚线并且用户数为 0。 不确定为什么会这样,我哪里错了?由于它之前工作正常,我相信我已经按
我正在使用 OpenGl ES 1.0 开发我的 Android 游戏,我想绘制虚线现在我使用这段代码来画我的线: gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // g
我正在尝试绘制 1 像素的虚线,但它总是绘制 2 像素的线。当前解决方案: let shapelayer = CAShapeLayer() let path = UIBezierPath() path
我这里有一个用 html 编码的菜单,但我需要一条虚线来跨越名称和价格,我将如何在这里做呢?我有点迷路了哈哈。 你可以在这里看到它。 http://mystycs.com/menu/menuifram
是否可以在 Chart.js 折线图上制作虚线?并使图表全宽?见附件样机。 这是我当前的代码(只是简单的例子): var ctx = document.getElementById("main
如何删除 JTabbedPane 上当前选定选项卡周围的虚线。 例如: 看到它周围的虚线了吗? 最佳答案 我刚刚找到了一个更好的方法: component.setFocusable(false); 关
我正在尝试使用 rgl 绘制一些 3d 形状,但我想使用虚线/虚线连接我的点。我怎样才能做到这一点?目前我有 require(rgl) p1 <- c(0,0,0) p2 <- c(1,0,0) p3
我是一名优秀的程序员,十分优秀!