我想在 python 的烛台图上绘制成交量剖面图,这会导致类似这样的结果。
我的主要 ohlc 数据将位于 pandas 数据框中。
Date, Open, High, Low, Close
2019-10-18, 54.09, 54.62, 53.35, 53.78
2019-10-17, 52.99, 54.16, 52.62, 53.93
2019-10-16, 52.92, 53.74, 52.51, 53.36
Run Code Online (Sandbox Code Playgroud)
然后我的卷信息将位于另一个像这样的数据框中。
Price, Volume
54.75, 150
54.50, 135
54.25, 140
54.00, 140
53.75, 125
53.50, 145
53.25, 130
53.00, 135
52.75, 155
52.50, 150
Run Code Online (Sandbox Code Playgroud)
我尝试过我所知道的几乎所有库,Matplotlib、Plotly、Bokeh。我尝试过简单地在烛台旁边绘制条形图,但缩放通常会关闭。我有兴趣使用 python 中的任何标准图表库,它可以以相当简单的方式产生这个结果。希望这里有人知道一些方法来做到这一点。
我使用plotly绘制了以下内容并得到了之前显示的结果图。X 是一天中的小时数,Y 是 0-1 之间的比例,Z 是级别为 {0,1,2} 的分类变量。
然而,尚不清楚为什么 X 似乎与我们习惯的 3D 笛卡尔位置相反的方向,即向下 (-) 和向上 (+)、向左 (-) 和向右 (+) 以及前面(-) 和背面 (+)。但X从前到后似乎不是增加而是减少。我是绘图新手,不知道如何翻转轴,使其从 0 到 1,而不是 1 到 0。我将非常感谢对此的帮助!
fig = px.scatter_3d(X_combined, x='x', y='y', z='z',
color='set', symbol='predictions', opacity=0.7)
fig.update_traces(marker=dict(size=12,
line=dict(width=5,
color='Black')),
selector=dict(mode='markers'))
Run Code Online (Sandbox Code Playgroud)
我无法将plotly_click事件绑定到plotly.js 中的条形图。从我见过的所有文档/帖子(请参阅上面的链接)来看,从事件传递到回调的数据的结构应如下所示:
{\n points: [{\n curveNumber: 2, // index in data of the trace associated with the selected point \n pointNumber: 2, // index of the selected point\n x: 5, // x value\n y: 600, // y value\n data: {/* */}, // ref to the trace as sent to Plotly.plot associated with the selected point\n fullData: {/* */}, // ref to the trace including all the defaults\n xaxis: {/* …Run Code Online (Sandbox Code Playgroud) 是否有一个 ggplot2 扩展包可以生成类似于五三八上的表格/水平条形图。理想情况下,我希望能够添加第二个甚至第三个条形图和其他文本列。
我一直在谷歌搜索并查看 ggplot 图表库,但还没有发现任何东西。
我想反转水平条形图图例的顺序。添加guides(fill = guide_legend(reverse = TRUE))到它时ggplot效果很好(参见第二个图)。但是,应用图例后,ggplotly()图例又恢复为默认顺序。
如何在不plotly改变条形顺序的情况下反转图例的顺序?
library(ggplot2)
library(dplyr)
data(mtcars)
p1 <- mtcars %>%
count(cyl, am) %>%
mutate(cyl = factor(cyl), am = factor(am)) %>%
ggplot(aes(cyl, n, fill = am)) +
geom_col(position = "dodge") +
coord_flip()
p1
Run Code Online (Sandbox Code Playgroud)

p2 <- p1 + guides(fill = guide_legend(reverse = TRUE))
p2
Run Code Online (Sandbox Code Playgroud)

plotly::ggplotly(p2)
Run Code Online (Sandbox Code Playgroud)
默认情况下,Plotly 在图例部分中单击其标签时隐藏该线。是否有任何其他键的组合shift/ctrl/alt/可以仅显示选定的行并隐藏所有其他行?
使用dcc.Upload,您可以在 Dash Plotly 仪表板中构建拖放或基于按钮的上传功能。但是,文档中对处理特定文件类型(例如.zip. 这是上传 html 的片段:
dcc.Upload(\n id=\'upload_prediction\',\n children=html.Div([\n \'Drag and Drop or \',\n html.A(\'Select Files\'),\n \' New Predictions (*.zip)\'\n ]),\n style={\n \'width\': \'100%\',\n \'height\': \'60px\',\n \'lineHeight\': \'60px\',\n \'borderWidth\': \'1px\',\n \'borderStyle\': \'dashed\',\n \'borderRadius\': \'5px\',\n \'textAlign\': \'center\',\n \'margin\': \'10px\'\n },\n accept=".zip",\n multiple=True\n)\nRun Code Online (Sandbox Code Playgroud)\n\n然后,当我尝试使用以下代码片段检查上传的文件时:
\n\n@app.callback(Output(\'output_uploaded\', \'children\'),\n [Input(\'upload_prediction\', \'contents\')],\n [State(\'upload_prediction\', \'filename\'),\n State(\'upload_prediction\', \'last_modified\')])\ndef test_callback(list_of_contents, list_of_names, list_of_dates):\n for content in list_of_contents:\n print(content)\nRun Code Online (Sandbox Code Playgroud)\n\n上传后的content-type为\xe2\x80\x98data:application/x-zip-compressed;base64\xe2\x80\x99。如何在 Dash Plotly 中处理这种类型的文件(例如将其提取到某个地方)?
\n\n在plotly论坛中提出了类似的问题,但没有答案:\n https://community.plot.ly/t/dcc-upload-zip-file/33976
\n在 python 中使用plotly,我想绘制具有多个 y 轴的条形图,因为一个轴的值明显大于另一个轴的值。

我尝试使用 来解决这个问题plotly.subplots.make_subplots,但我无法让它们像正常的绘图功能那样彼此相邻地绘图barmode='group'。
import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig = make_subplots(specs=[[{'secondary_y': True}]])
fig.add_bar(name='group 1',x=x1, y=y1, secondary_y=False)
fig.add_bar(name='group 2', x=x2, y=y2, secondary_y=True)
fig.update_layout(
xaxis_title='x-axis',
yaxis_title='y-axis')
Run Code Online (Sandbox Code Playgroud)
条形图彼此后面,我修改了 make_suplots 的参数但无济于事。
我怎样才能得到想要的结果?
编辑:
我尝试了雅罗斯拉夫的答案,它确实有效。感觉像是一个次优的实现,并且在第二个 y 轴上对值进行了关键切割。
我正在 R 中的绘图中添加一个变量选择器(遵循通常的方法,即隐藏图中不必要的痕迹)
\n\nlibrary(plotly)\n\ndat <- mtcars\ndat$cyl <- factor(dat$cyl)\ndat$car <- rownames(mtcars)\n\ndat %>% \n plot_ly(x = ~car, y = ~mpg,\n name=\'mpg\', type=\'scatter\', mode=\'markers\') %>%\n add_trace(y = ~hp, name = \'hp\', type=\'scatter\', mode=\'markers\') %>%\n add_trace(y = ~qsec, name = \'qsec\', type=\'scatter\', mode=\'markers\') %>%\n layout(\n updatemenus = list(\n list(\n type = "list",\n label = \'Category\',\n buttons = list(\n list(method = "restyle",\n args = list(\'visible\', c(TRUE, FALSE, FALSE)),\n label = "mpg"),\n list(method = "restyle",\n args = list(\'visible\', c(FALSE, TRUE, FALSE)),\n label = "hp"),\n list(method …Run Code Online (Sandbox Code Playgroud) plotly ×10
python ×6
r ×3
ggplot2 ×2
ggplotly ×2
matplotlib ×2
plotly-dash ×2
axis ×1
bokeh ×1
data-science ×1
plotly.js ×1
r-plotly ×1
scatter ×1
seaborn ×1