如何在同一页面的图片中添加多个图形显示?我正在尝试将 html.Div 组件添加到以下代码中以更新页面布局以在单个页面上添加更多类似的图形,但是这些新添加的图形不会显示在页面上,只能在图片中显示旧图形。我应该修改什么元素,比如说在浏览器的 dash 应用程序的单页上添加 3 次在上传的图像中显示的图形?
import dash
import dash_core_components as dcc
import dash_html_components as html
i[enter image description here][1]mport plotly.express as px
import pandas as pd
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
"Amount": [4, 1, 2, 2, 4, 5],
"City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})
fig = px.bar(df, x="Fruit", y="Amount", …Run Code Online (Sandbox Code Playgroud) 对不起,今天让你忙着处理阴谋问题.这将是另一个:如何在plotly的新3D散点图上显示图例和轴标签?
例如,如果我在2D中有以下散点图生成一切正常,我添加了另一个维度,但轴标签不再显示(请参阅下面的代码),并且图例也有同样的问题.有小费吗?谢谢!


traces = []
for name in ('Iris-setosa', 'Iris-versicolor', 'Iris-virginica'):
trace = Scatter3d(
x=Y[y==name,0],
y=Y[y==name,1],
z=Y[y==name,2],
mode='markers',
name=name,
marker=Marker(
size=12,
line=Line(
color='rgba(217, 217, 217, 0.14)',
width=0.5
),
opacity=0.8
)
)
traces.append(trace)
data = Data(traces)
layout = Layout(xaxis=XAxis(title='PC1'),
yaxis=YAxis(title='PC2'),
zaxis=ZAxis(title='PC3')
)
fig = Figure(data=data, layout=layout)
py.iplot(fig)
Run Code Online (Sandbox Code Playgroud) 我正在使用plotly for python而我无法设置x和y轴因此它们可以具有相同的比例:
这是我的布局:
layout = Layout(
xaxis=XAxis(
range=[-150, 150],
showgrid=True,
zeroline=True,
showline=True,
gridcolor='#bdbdbd',
gridwidth=2,
zerolinecolor='#969696',
zerolinewidth=4,
linecolor='#636363',
linewidth=6
),
yaxis=YAxis(
range=[-150,150],
showgrid=True,
zeroline=True,
showline=True,
gridcolor='#bdbdbd',
gridwidth=2,
zerolinecolor='#969696',
zerolinewidth=4,
linecolor='#636363',
linewidth=6
)
)
Run Code Online (Sandbox Code Playgroud)
然后我得到这样的东西!

为什么x和y的比例不同?这将影响我的可视化.
如何获得带方形单元格的网格?
如何在R中使用Plotly创建子图网格?
官方网站有这个很好的Python示例:
在Python代码有权选择rows=2和cols=2,但在R上的subplot功能刚刚参数nrows,没有ncols.
我在R中尝试了这个例子,但是nrows没有按预期接缝工作:
# Basic subplot
library(plotly)
p <- plot_ly(economics, x = date, y = uempmed)
subplot(p,p,p,p,
margin = 0.05,
nrows=2
) %>% layout(showlegend = FALSE)
Run Code Online (Sandbox Code Playgroud)
它们在一条线而不是在网格中.看结果:
这是R suplots页面供参考.不幸的是,使用ggplotly对我来说不是一个选择,就像这样
这是一个错误.Plotly团队非常快,仅在3天内修复(点击此处查看)!Github版本已经更新.很好!
如何使用代码从R中将Plotly图表导出为图像?(不使用图表上的导出按钮).
例如,来自Plotly站点的此代码创建此图表:
library(plotly)
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
plot_ly(d, x = carat, y = price, text = paste("Clarity: ", clarity),
mode = "markers", color = carat, size = carat)
Run Code Online (Sandbox Code Playgroud)
如何将其保存为图像?
官方网站在python中有这个材料,但我在R中找不到类似的东西.
我正在创建条形图,plotly其中y轴代表0-1内的百分比或份额.y轴显示为0.05而不是5.0%.
有没有办法显示y轴刻度标签%##?
我尝试过使用tickformat = "%"但似乎没有用.
Uncaught ReferenceError: Plotly is not defined我的页面加载时出现错误。以下代码位于渲染绘图的 div 元素下方,但在侦听器Plotly.newPlot('myDiv', dataPlot, layout);内的行socket.on上是抛出此错误的位置。
var dataPlot = [{
x: ['a', 'b', 'c', 'd'],
y: [0, 0, 0, 0],
type: 'bar'
}];
var layout = {
autosize: false,
width: 500,
height: 500,
margin: {
l: 50,
r: 50,
b: 100,
t: 100,
pad: 4
}
};
// Listener, whenever the server emits 'updatechat', this updates the chat body
socket.on('updatechat', function (username, data) {
$('#conversation').append('<b>'+username + ':</b> ' + data + …Run Code Online (Sandbox Code Playgroud) 我试图制作一个气泡图,其中每种颜色代表不同的珊瑚种类代码,气泡的大小代表个体的大小(以米为单位),但也缩放到x或y轴,它们也按比例缩放米.
我还想为我目前plotly在R中使用的个人的大小添加一个额外的图例,但是可以使用R或Python中的其他模块.
我已经能够通过物种相对容易地获得颜色,但我正在努力按尺寸缩放气泡.有没有人以前做过这个或知道任何作弊才能让它发挥作用?
#Example Data
Species <- c('SSID','PAST','CNAT','SSID','MMEA','PAST')
Dist <- c(7.1,4.0,6.4,8.0,8.1,8.9)
XDist <- runif(6, 0.0, 1.0)
Transect <- c(1,2,1,1,3,2)
Width <- c(10,15,100,45,60,27)
Data <- data.frame(Transect, Species, Dist, XDist, Width)
XDist <- Data$Transect - 1
Data$XDist <- Data$XDist + XDist
library(plotly)
k <- plot_ly(Data, x = ~XDist, y = ~Dist, type = 'scatter', mode =
'markers',
size = ~Width ,marker = list(sizemode = 'diameter', opacity = 1,
symbol = ifelse(data$Disease == 'Y', "circle-open", "circle"),
line = list(width = 5)), …Run Code Online (Sandbox Code Playgroud) 使用plotly的subplots()时,如何删除图例中的重复项?
这是我的MWE:
library(plotly)
library(ggplot2)
library(tidyr)
mpg %>%
group_by(class) %>%
do(p = plot_ly(., x = ~cyl, y = ~displ, color = ~trans, type = 'bar')) %>%
subplot(nrows = 2, shareX = TRUE, titleX = TRUE) %>%
layout(barmode = 'stack')
Run Code Online (Sandbox Code Playgroud) 使用 plotly 导出静态图表时出现小问题。
Plotly 无法正确识别我安装了 orca,但仍然存在与缺少 orca 相关的错误。我尝试更改 orca 目录,但它仍然无法正常工作。任何人都知道出了什么问题?
我的代码:
import plotly.graph_objects as go
import orca
import plotly
#%%
fig = go.Figure(data=go.Candlestick(x=pricedata.index,
open=pricedata['bidopen'],
high=pricedata['bidhigh'],
low=pricedata['bidlow'],
close=pricedata['bidclose']),)
#%%
fig.show()
#%%
plotly.io.orca.config.executable = r'C:\Users\Kuba\AppData\Local\Programs\Python\Python37\Lib\site-packages\orca'
plotly.io.orca.config.save()
#%%
fig.write_image("images/fig1.png")
Run Code Online (Sandbox Code Playgroud)
这里描述了如何解决它,但它对我不起作用:
https://plot.ly/python/orca-management/#configuring-the-executable
orca 版本是 1.5.1
谢谢。
B.
编辑:
错误消息:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
c:\Users\Kuba\Documents\GitHub\frstalg\FXCM Stuff\LiveMyStrategyNOTEBOOK-20191017.py in
1
----> 2 fig.write_image("images/fig1.png")
~\AppData\Local\Programs\Python\Python37\lib\site-packages\plotly\basedatatypes.py in write_image(self, *args, **kwargs)
2686 import plotly.io as pio
2687
-> 2688 return pio.write_image(self, *args, **kwargs)
2689
2690 # Static …Run Code Online (Sandbox Code Playgroud) plotly ×10
r ×5
python ×4
ggplot2 ×2
plot ×2
r-plotly ×2
axis-labels ×1
data-science ×1
datagrid ×1
html ×1
javascript ×1
orca ×1
plotly-dash ×1
socket.io ×1
subplot ×1