有没有办法控制水平线和垂直线的起点和终点plotly?
import plotly.graph_objects as go
fig = go.Figure(data=go.Scatter())
fig.add_vline(x=1, line_width=2, line_dash="dash", line_color="green")
fig.add_hline(y=2, line_width=2, line_dash="dash", line_color="red")
fig.show()
Run Code Online (Sandbox Code Playgroud)
上面的代码将绘制线条,但在整个屏幕上
我想做类似的事情:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize = (10,7))
ax.hlines(y=2, xmin='July', xmax='Aug', linewidth=2, color='red', linestyles = 'dotted')
ax.axvline(x = 1,color = 'green', linestyle = 'dotted', linewidth = 2)
Run Code Online (Sandbox Code Playgroud) 我正在使用yfinance和plotly库(python 2.7)来获取欧元/美元数据,然后创建烛台图。
这是我从雅虎财经下载数据的代码:
import yfinance as yf
data = yf.download(tickers='EURUSD=X', period='1d', interval='30m')
Run Code Online (Sandbox Code Playgroud)
示例输出:
data.tail(10)
Open High Low Close Adj Close Volume
Datetime
2022-02-25 17:30:00+00:00 1.125239 1.125239 1.124101 1.124354 1.124354 0
2022-02-25 18:00:00+00:00 1.124480 1.125873 1.124480 1.125492 1.125492 0
2022-02-25 18:30:00+00:00 1.125619 1.126507 1.125619 1.126126 1.126126 0
2022-02-25 19:00:00+00:00 1.125999 1.126507 1.125492 1.126253 1.126253 0
2022-02-25 19:30:00+00:00 1.126634 1.126888 1.125366 1.126634 1.126634 0
2022-02-25 20:00:00+00:00 1.126888 1.127015 1.126126 1.126634 1.126634 0
2022-02-25 20:30:00+00:00 …Run Code Online (Sandbox Code Playgroud) 我有一个有 4 列的 pandas 数据框,类似于这样的东西-
a = [19.1, 18.4, 19.2, 18.2, 17.4]
b = [62.28, 57.07, 55.61,54.09,54.6]
c = [18.68,17.79,17.03,18.62,18.62]
d = [73.03,71.63,70.22,71.77,71.77]
Run Code Online (Sandbox Code Playgroud)
我正在使用 Plotly Express 绘制折线图以可视化每一列。我想单独为 a 和 c 列绘制虚线(虚线),为 b 和 d 列绘制常规线。如何使用 Plotly Express 为 a 列和 c 列创建虚线?
我在plotly(R) 中创建了一个带有辅助y 轴的图。我使用hoverfunction x Unified,但我想更改标题中的日期格式。数据是每周数据,所以现在你在胡佛中看到:2022年1月1日,但我想看到的是:1月1日(第01周)或1月1日 - 22年1月8日。我用tickprefix尝试了一些东西,但后来也刻度在变化,而不仅仅是悬停。
我现在的演示代码是:
library(plotly)
# dummy data
df_data1 = data.frame(date_input = seq(as.Date('2022/01/01'), as.Date('2022/07/01'), by="week")
, value=1:26)
df_data2 = data.frame(date_input = seq(as.Date('2022/01/01'), as.Date('2022/07/01'), by="week")
, value2=3:28)
plot1 <- plot_ly()
plot1 <- plot1 %>%
add_trace(data = df_data1, x = ~date_input, y = ~value
, type = 'scatter', mode = "lines", yaxis = "y", line = list(color = '#E64B35FF', opacity = 0.8)
, showlegend = FALSE
, hovertemplate = ~paste('# Value1: %{y:.0f}<extra></extra>')) %>%
add_trace(data = df_data2, x = …Run Code Online (Sandbox Code Playgroud) 我想根据从 API 获取的 .csv 文件创建一个简单的绘图图表。
我导入库,传递数据帧,然后收到错误:
TypeError: <class 'numpy.typing._dtype_like._SupportsDType'> is not a generic class
Run Code Online (Sandbox Code Playgroud)
代码:
import plotly.express as px
df=pd.read_csv('file.csv')
Run Code Online (Sandbox Code Playgroud)
可能是什么问题,这个错误意味着什么?
完整的错误回溯:
import plotly.express as px
df=pd.read_csv('file.csv')
Run Code Online (Sandbox Code Playgroud) 我正在使用plotly 进行绘图,并使用plotly 表达折线图,该折线图使用fig.update_figure 进行更新。然而 update_figure 中的每个更新参数都会导致绘图被绘制为图形输出,所以我最终得到了四个中间图和最后一个。如何抑制Fig.update_figue的输出?我认为覆盖参数会有帮助,但显然没有。输出如下所示
这是实际的代码:
import plotly
fig_Fahmy = plotly.express.line(
data_melt3,
x="Heat data",
y="Flow data",
color="variable",
height=800,
width=1300,
title="Fahmy plot of heat flow ~ cumulative heat",
labels={
"Flow data": "Heat flow, W",
"Heat data": "Cumulative heat, J",
"variable": ""
}
)
fig_Fahmy.update_traces(line=dict(width=2))
fig_Fahmy.update_xaxes(
linewidth=1,
linecolor='black',
mirror=True,
ticks='inside',
showline=True,
gridcolor="white",
zerolinecolor="darkgray",
title_font=dict(size=20),
tickfont=dict(size=15),
ticklen=10,
tickwidth=2
)
fig_Fahmy.update_yaxes(
linewidth=1,
linecolor='black',
mirror=True,
ticks='inside',
showline=True,
gridcolor="white",
zerolinecolor="darkgray",
title_font=dict(size=20),
tickfont=dict(size=15),
ticklen=10,
tickwidth=2
)
fig_Fahmy.update_layout(
overwrite=True,
plot_bgcolor="rgba(0, 0, 0, 0)",
legend=dict(itemsizing='constant'),
legend_font=dict(size=15),
title_font=dict(size=25)
) …Run Code Online (Sandbox Code Playgroud) 我想创建这样的卫星地图:https ://plotly.com/python/mapbox-layers/
我尝试用我的数据(来自法国)重现此代码:
import pandas as pd
us_cities = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")
import plotly.express as px
fig = px.scatter_mapbox(us_cities, lat="lat", lon="lon", hover_name="City", hover_data=["State", "Population"],
color_discrete_sequence=["fuchsia"], zoom=3, height=300)
fig.update_layout(
mapbox_style="white-bg",
mapbox_layers=[
{
"below": 'traces',
"sourcetype": "raster",
"sourceattribution": "United States Geological Survey",
"source": [
"https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}"
]
}
])
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
Run Code Online (Sandbox Code Playgroud)
但我无法按我想要的方式缩放。
我如何选择底图以获得数据区域的良好分辨率?您是否知道一组底图,我可以从中选择一张以法国为中心的底图?
如何默认选择图例中的一项,而取消选择其他项目?
我希望最初的情节看起来像这样:
#prepare thr chart
fig = px.line(df, x='date', y='diesel_price', color='region',
title='Diesel price in the US',
labels={'date':'Date',
'diesel_price':'Price ($)', 'region':'Region'})
app.layout = html.Div([
html.H4('Metrics for trucking companies'),
dcc.Graph(figure=fig),
])
if __name__ == '__main__':
app.run_server(debug=True, host='0.0.0.0', port=8050)
Run Code Online (Sandbox Code Playgroud) 我已经有一个用plotly制作的散点图(交互式),我想在特定坐标中添加一个点,不一定是交互式的(以标记中位数)。我怎样才能添加它?
\nfig = px.scatter(df_b,\n x="EAD", \n y="RAR",\n size="Margen_bruto",\n hover_name="Cliente",\n hover_data={'EAD': ':.0f', 'RAR': ':.0%', 'Margen_bruto': ':.0f'},\n size_max=30,\n trendline='lowess',\n trendline_color_override='black',\n trendline_scope='overall',\n title="B\xc3\x89LGICA dic 2019 - 46 clientes")\nRun Code Online (Sandbox Code Playgroud)\n我已经使用过像fig.add_annotationand这样的函数fig.add_hline等函数向我的图表添加文本和线条,但我似乎无法仅添加一个点。
我正在运行一些闪亮的应用程序。然而,有些包含可能引起公众兴趣的图形。因此,我正在 Infogram 中寻找类似于下图的解决方案,但可以从 Poltly 的 ( plotly) 工具栏编辑图表,尤其是颜色。这是 Infogram 的玩具示例。
是否可以通过编辑 Plotly 在 Shiny R 中做类似的事情?在工具栏中添加一个小的绘图配置按钮是理想的选择。如果没有,您是否知道有类似的软件包可以实现此目的?
“顶部”将是:
请注意工具栏上的配置按钮(齿轮)设计。这本身并不存在。
一个 R 代码示例
library(plotly)
fig <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
fig
Run Code Online (Sandbox Code Playgroud)