Creating a plot by adding one column at a time works just fine
exPlot <- plot_ly(data.table(matrix(1:9,ncol = 3)))
theCols <- c("V2","V3")
exPlot <- exPlot %>% add_lines(x = ~V1, y = ~get(theCols[1]), type = "scatter",mode = "lines")
exPlot <- exPlot %>% add_lines(x = ~V1, y = ~get(theCols[2]), type = "scatter",mode = "lines")
exPlot
Run Code Online (Sandbox Code Playgroud)
but if I try to do the same thing in a for loop, it only displays the second trace, overwriting the first one.
exPlot <- plot_ly(data.table(matrix(1:9,ncol = 3))) …Run Code Online (Sandbox Code Playgroud) 在像下面这样的图表中,我想将千位分隔符更改为点“.”,但我不知道如何使用该tickformat参数来获取它。
require(plotly)
p <- plot_ly(x=~c(2012,2013,2014,2015,2016), y=~c(1200000,975000,1420000,1175000,1360000), type='bar') %>%
layout(yaxis = list(title="Income in €", tickformat=",d", gridcolor = "#bbb"), xaxis = list(title="Year"), margin=list(l=80))
p
Run Code Online (Sandbox Code Playgroud)
我正在自动化几个双周报告,所以我决定使用 plot.ly 创建一个线图。此线图具有不同数量的跟踪,具体取决于正在运行的报告。
我已经能够成功创建绘图,但我发现的所有方法都无法在我的电子邮件中内联显示绘图。这是我的代码:
SMTP_SERVER = "smtp.office365.com"
SMTP_PORT = 587
SMTP_USERNAME = username
SMTP_PASSWORD = password
EMAIL_TO = email_to
EMAIL_FROM = email_from
#here we loop through our data-set and pull out rows to make different traces
for deal in winGraph['DEAL_IDENTIFIER'].unique():
matched_rows = winGraph.loc[winGraph['DEAL_IDENTIFIER'] == deal]
date = matched_rows.DATE.tolist()
winRate = matched_rows.WIN_RATE.tolist()
traces.append(
go.Scatter(
x = date,
y = winRate,
name = str(deal)
)
)
plotly.tools.set_credentials_file(username = 'username', api_key = 'api_key')
fig = dict(data = traces)
imageURL = py.plot(fig,auto_open = False, …Run Code Online (Sandbox Code Playgroud) 当我在plotly堆积条形图中只添加了一条轨迹时,图例丢失了。
我的数据集如下:
myDF <- structure(list(Year = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "2017", class = "factor"),
Month = c("Mar", "Mar", "Mar", "Apr", "Apr", "Apr"), Date = structure(c(17241,
17242, 17242, 17259, 17260, 17261), class = "Date"), Quarter = c("Q1",
"Q1", "Q1", "Q2", "Q2", "Q2"), Week = structure(c(2L, 2L,
2L, 3L, 3L, 3L), .Label = c("2017-03-05", "2017-03-12", "2017-04-02"
), class = "factor"), NPS = structure(c(NA, NA, NA, 3L, 3L,
3L), .Label = c("Detractor", "Passive", "Promoter"), class = "factor")), …Run Code Online (Sandbox Code Playgroud) 默认情况下,一个情节情节有他们的标志和文字,如“用情节制作”(右上角)。我有一个高级帐户,想删除该徽标。
这是一个完成最终情节的小代码片段:
plotly.tools.set_credentials_file(username='username', api_key='xxxxxxx')
list_df = pd.read_csv('my_csv_file.csv')
names_df = list_df['Name']
trace = go.Scatter(
x = list_df['Abc'],
y = list_df['Xyz'],
visible=True,
text=names_df,
hoverinfo = 'text',
hoverlabel=dict(bgcolor='white'),
name='ABC',
line = dict(color='#17BECF'),
mode = "markers",
marker=dict(size=8),
showlegend=False,
opacity = 0.8
)
data = [trace]
layout = go.Layout(
title='Lyout Name',
hovermode = 'closest',
xaxis=dict(
title='Title X axis',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
),
yaxis=dict(
title='Title Y axis',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
)
)
config = {
'scrollZoom': False,
'displayModeBar': …Run Code Online (Sandbox Code Playgroud) 是否可以将两个堆叠的条形图并排放置,每个条形图都来自一个列?
这是我的 df:
Field Issue
Police Budget cuts
Research Budget cuts
Police Time consuming
Banking Lack of support
Healthcare Lack of support
Research Bureaucracy
Healthcare Bureaucracy
Banking Budget cuts
Run Code Online (Sandbox Code Playgroud)
我想要一个 Field 的堆积条形图,旁边是一个按字段排列的问题堆积条形图。
谢谢你们!
我看到以下渲染器可用:
Default renderer: 'browser'
Available renderers:
['plotly_mimetype', 'jupyterlab', 'nteract', 'vscode',
'notebook', 'notebook_connected', 'kaggle', 'azure', 'colab',
'json', 'png', 'jpeg', 'jpg', 'svg', 'pdf', 'browser',
'firefox', 'chrome', 'chromium', 'iframe', 'iframe_connected',
'sphinx_gallery']
Run Code Online (Sandbox Code Playgroud)
但我不知道如何让 pycharm 在 IDE 中显示输出,就像我用 matplotlib 做图形一样。
如何才能做到这一点?
编辑:
这是我使用的代码,来自 plotly 的示例:
fig = go.Figure(
data=[go.Bar(y=[2, 1, 3])],
layout_title_text="test"
)
fig.show()
Run Code Online (Sandbox Code Playgroud)
这将打开一个浏览器选项卡以显示在 pycharm 调试器中运行时的图形。
编辑2:
我从一年前看到一个类似的问题,没有解决方案:
我想创建交互式甘特图(或序列图)来显示多个处理器上的任务调度。
我找到了这个库,它生成了非常好的交互式甘特图。不幸的是,plotly-Gantt 只适用于日期,而不适用于数值,就像我对日程表的运行时值一样。
是否有可能用数值绘制甘特图?
代码示例:(我想使用这样的东西)
import plotly.figure_factory as ff
df = [dict(Task="Job A on Core 0", Start=0, Finish=10),
dict(Task="Job B on Core 1", Start=2, Finish=8),
dict(Task="Job C on Core 0", Start=11, Finish=12)]
fig = ff.create_gantt(df)
fig.show()
Run Code Online (Sandbox Code Playgroud) 谁能帮我发现这里的错误?
fig = go.Figure()
fig.add_trace(
go.Choroplethmapbox(
geojson=counties,
locations=df_se['FIPS'], z=df_se['use_values'],
colorscale="Viridis", zmin=min(df_se['use_values']), zmax=max(df_se['use_values']),
marker_opacity=0.5, marker_line_width=0
))
fig.add_trace(
go.Scattergeo(
lon = df_jake['lng'],
lat = df_jake['lat'],
text = df_jake['Name']+', '+df_jake['Link'],
mode = 'markers'
))
fig.update_layout()
fig.show()
Run Code Online (Sandbox Code Playgroud)
它只是显示为空白。我可以分别绘制 Chloropleth 和 ScatterGeo
谢谢!
我正在学习使用 pyplot.express 并努力解决以下设计问题:在多面图中,每个子图的轴标题都会重复(在示例中为“花瓣宽度 (cm)”)。有没有办法使用 pyplot.express 为分面图上的所有子图获取单轴标签?
谢谢,迈克尔
最小的例子:
from sklearn.datasets import load_iris
import plotly.express as px
import pandas as pd
import numpy as np
# import iris-data
iris = load_iris()
df= pd.DataFrame(data= np.c_[iris['data'], iris['target']], columns= iris['feature_names'] + ['target'])
df['species'] = pd.Categorical.from_codes(iris.target, iris.target_names)
# plot using pyplot.express
fig = px.bar(df, x="sepal length (cm)", y="petal width (cm)", color = 'petal length (cm)', facet_row="species")
fig.show()
Run Code Online (Sandbox Code Playgroud)