我有一个plotly.js条形图,我试图得到分类轴的顺序正确.每个类别都有一个单独的栏,但有时它们是绿色的,有时它们是黄色的.条形应该从最高到最低顺序排列,但似乎根据不同的填充顺序排列它们.
数据:
var data = [
{
"marker": {
"color": "#006666"
},
"x": ["A:0122", "A:0121", "A:0434", "A:0838", "A:0083", "A:0081", "A:0687"],
"y": [1246.0, 1096.0, 1000.0, 200.0, 0.0, 0.0, 0.0],
"name": "Green",
"type": "bar"
},
{
"marker": {
"color": "#C87B31"
},
"x": ["A:0169", "A:0175"],
"y": [270.0, 0.0],
"name": "Yellow",
"type": "bar"
}
];
Run Code Online (Sandbox Code Playgroud)
布局:
var layout = {
"margin": {
"t": 0
},
"barmode": "stack",
"tickangle": -90,
"showlegend": true,
"xaxis": {
"title": "Idea",
"tickmode": "array",
"tickvals": ["A:0122", "A:0121", "A:0434", "A:0169", "A:0838", "A:0083", …Run Code Online (Sandbox Code Playgroud) 我正在使用python3.我有1分钟频率的报价系列.报价仅在交易时间内提供.我尝试使用plotly绘制它,但在非交易时间和周末有差距.我怎样才能使这个情节连续?
我的代码就像
ifBasisPlot=go.Scatter( x=ifBasis.date, y=ifBasis.basis, line=go.Line(width=1,color='blue'), name='basis' )
data = go.Data([ifBasisPlot])
ifBasisPlot_url = py.plot(data, filename='ifBasisPlot', auto_open=False,)
Run Code Online (Sandbox Code Playgroud)
情节和数据在这里:https://plot.ly/~shuaihou96/14/if/
这是我使用的程序:
library(plotly)
mydata = read.csv("data_to_plot.txt")
df = as.data.frame(mydata)
p <- df %>%
group_by(X) %>%
plot_ly(x = ~Y, y = ~X, z = ~Z, type = "scatter3d", mode = "lines")
p
Run Code Online (Sandbox Code Playgroud)
以下是“ mydata”的摘录:
df [1:12,]
XYZ
1 1 0.2818017 0.0005993884
2 1 0.2832173 0.0007896421
3 1 0.2846330 0.0010293849
4 1 0.2860487 0.0013282462
5 1 0.2874643 0.0016969544
我想在X轴上反转X值,但是找不到如何修改程序。plotly语法的细节对我来说还是很模糊的。有人可以提供一些帮助吗?非常感谢。
在Plotly Dash中更新下拉框后,屏幕左下角会出现一个撤消按钮,并且不会消失.
我该如何删除它?
我有一份在Jupyter Notebook中创建的报告。我出于审美原因希望将输出(图)居中。
我已经尝试过这里给出的答案:
但是,这不起作用。
我确实发现这可以在Stackoverflow上工作(ipython Notebook中的居中对齐输出)
CSS = """
.output {
align-items: center;
}
"""
HTML('<style>{}</style>'.format(CSS))
Run Code Online (Sandbox Code Playgroud)
但是,虽然它使图居中,但当图宽且不需要居中时,它会扩展它并使它比我不需要的页面更宽。我已经尝试过像上面说的那样调整输出边距区域,但是它要么将其再次推到左侧,要么将其挤压到需要滚动条的位置(再次,我不想这么做)
任何人有任何建议吗?我认为这将是标准且容易的,但显然不是(如果无法实现,仅将代码块居中的方法将是一个完美的解决方法?)
即此表的中心:
这是由以下代码产生的:
df = pd.DataFrame(a01)
new_df01 = df[['Call','FirstReceivedDate','Value']]
new_df01['month'] = pd.Categorical(new_df01['FirstReceivedDate'].dt.strftime('%b'),
categories=vals, ordered=True)
groupA01 = new_df01.groupby(['Call']).agg({'Value':sum, 'FirstReceivedDate':'count'}).rename(columns={'FirstReceivedDate':'Count'})
groupA01['Value'] = groupA01['Value'].map('{:,.2f}'.format)
def hover(hover_color="#F1C40F"):
return dict(selector="tr:hover",
props=[("background-color", "%s" % hover_color)])
styles2 = [
hover(),
dict(selector="th", props=[("font-size", "80%"),
("font-family", "Gill Sans MT"),
("color",'white'),
('background-color', 'rgb(11, 48, 79)'),
("text-align", "center")]),
dict(selector="td", props=[("font-size", "75%"),
("font-family", "Gill Sans MT"),
("text-align", "center")]),
dict(selector="tr", props=[("line-height", "11px")]), …Run Code Online (Sandbox Code Playgroud) 使用plotly我希望每个表面都有不同的颜色.
library(plotly)
t1 <- seq(-3, 3, 0.1); t2 <- seq(-3, 3, 0.1)
p1 <- matrix(nrow = length(t1), ncol = length(t2))
p2 <- matrix(nrow = length(t1), ncol = length(t2))
p8a1 <- 1.2
p8a2 <- 1
p8d <- -1
p8b1 <- 0.7
p8b2 <- 0.6
for (i in 1:length(t2)) {
for (j in 1:length(t1)) {
p1[i, j] <- 1 / (1 + exp(-1.7 * (p8a1 * t1[j] + p8a2 * t2[i] + p8d)))
p2[i, j] <- (1 / (1 + …Run Code Online (Sandbox Code Playgroud) 我希望通过plotly获得与此ggplot代码相同的结果:
mtcars %>% add_rownames('car') %>%
ggplot(aes(x = mpg,
y = disp,
color = as.factor(gear),
shape = as.factor(cyl))) +
geom_point()
Run Code Online (Sandbox Code Playgroud)
我的情节代码是:
library(dplyr)
mtcars %>% add_rownames('car') %>%
plot_ly(x = ~mpg,
y = ~disp,
text = ~car,
color = ~as.factor(gear),
symbol = ~as.factor(cyl),
mode = 'markers')
Run Code Online (Sandbox Code Playgroud)
有没有办法让ggplot有类似的传说?
我在Python 3.6.3中使用plotly,我正在尝试像这里一样做一个Choropleth地图.我想改变悬停在地图上方时出现的属性.也就是说,例如,如果我们考虑加利福尼亚的第一张地图和悬停,它看起来像:
我想更改显示的内容的字体大小和框的大小.有没有办法访问这些?
以下是生成它的代码:
import plotly.plotly as py
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv')
for col in df.columns:
df[col] = df[col].astype(str)
scl = [[0.0, 'rgb(242,240,247)'],[0.2, 'rgb(218,218,235)'],[0.4, 'rgb(188,189,220)'],\
[0.6, 'rgb(158,154,200)'],[0.8, 'rgb(117,107,177)'],[1.0, 'rgb(84,39,143)']]
df['text'] = df['state'] + '<br>' +\
'Beef '+df['beef']+' Dairy '+df['dairy']+'<br>'+\
'Fruits '+df['total fruits']+' Veggies ' + df['total veggies']+'<br>'+\
'Wheat '+df['wheat']+' Corn '+df['corn']
data = [ dict(
type='choropleth',
colorscale = scl,
autocolorscale = False,
locations = df['code'],
z = df['total exports'].astype(float),
locationmode = 'USA-states',
text …Run Code Online (Sandbox Code Playgroud) 我创建了一个shiny应用程序来显示大型数据集的相关热图.按下热图贴图后,将显示相应的散点图.
但是,我需要制作其中几个应用程序,这超出了我的发布限制shinyapps.io.我的公司不愿意升级到付费计划.我尝试使用其他方法发布应用程序,如RInno无效(我认为应用程序太复杂了?).
如果有人能告诉我如何plotly单独生产同样的东西而不是shiny,我会永远感激.我相信crosstalk可能是将热图贴图链接到散点图的路径?
谢谢
这里的例子.
library(plotly)
library(shiny)
# compute a correlation matrix
correlation <- round(cor(mtcars), 3)
nms <- names(mtcars)
ui <- fluidPage(
mainPanel(
plotlyOutput("heat"),
plotlyOutput("scatterplot")
),
verbatimTextOutput("selection")
)
server <- function(input, output, session) {
output$heat <- renderPlotly({
plot_ly(x = nms, y = nms, z = correlation,
key = correlation, type = "heatmap", source = "heatplot") %>%
layout(xaxis = list(title = ""),
yaxis = list(title = ""))
}) …Run Code Online (Sandbox Code Playgroud) 我从切换matplotlib到plotly主要是绘制在2D / 3D流畅的动画。我想绘制由多个圆/球组成的机器人的运动。
机器人的不同身体部位具有不同的大小,圆圈需要准确地表示出来。是否有办法plotly来指定数据单元标记的大小?例如,我想绘制一个5m x 5m(x5m)的截面,其中半径为0.1m的圆/球沿着不同的轨迹运动。
在matplotlib中,我知道两种选择。一种是使用补丁(matplotlib.patches.Circle)。第二种方法是绘制点并通过考虑dpi正确缩放其marker_size(请参阅matplotlib的此问题的答案)。
A)是否可以对图形进行3D动画处理?
要么
B)有没有办法以数据单位指定标记的大小或正确缩放sizeref属性?
# Point with radius 2 (approx.)
from plotly.offline import plot
import plotly.graph_objs as go
trace = go.Scatter(x=[4], y=[4],
mode='markers',
marker={'size': 260, 'sizeref': 1}) # ???
layout = dict(yaxis=dict(range=[0, 10]),
xaxis=dict(range=[0, 10]))
fig = dict(data=[trace], layout=layout)
plot(fig, image_height=1000, image_width=1000)
Run Code Online (Sandbox Code Playgroud)
缩放marker_size的问题是,只有当您不放大或缩小图像时,图像才是正确的,因为marker_size保持恒定。因此,更干净的方法是直接以数据单位指定圆圈的大小。
plotly ×10
python ×4
r ×3
axis ×1
choropleth ×1
ggplotly ×1
hover ×1
interactive ×1
javascript ×1
plotly-dash ×1
python-3.x ×1
reversing ×1
shiny ×1