我有一个 Python Plotly 气泡图,其中每个标记的直径必须对应于现实世界的距离。Plotly 是否可以在放大/缩小时动态调整气泡图上标记的大小?具体来说,我想在放大时使标记变大,在缩小时使标记变小。
以下是Plotly 气泡图文档中的当前行为:
正如您所看到的,无论缩放如何,标记在屏幕上都保持相同的大小。
我收到错误:
TypeError: scatter() got an unexpected keyword argument 'trendline_options'
Run Code Online (Sandbox Code Playgroud)
当尝试使用plotlyexpress调整最低趋势线的平滑度时。
这是我的图表代码:
fig = px.scatter(dfg, x="Yr_Mnth", y="Episode_Count", color = "Target",
labels={"Episode_Count": tally + " per Shift",
"Target":"Target",
"Yr_Mnth": "Date" },
trendline='lowess',trendline_options= dict(frac=0.1), title="Aggregate Behavior Data: " + patient + " - " + today)
fig.update_xaxes(tickangle=45,)
fig.update_layout(template = 'plotly_white',hovermode="x unified")
Run Code Online (Sandbox Code Playgroud)
数据集(dfg):
Yr_Mnth Target Episode_Count
2020-08-01 Aggression 0.09
2020-08-01 Elopement 0.00
2020-08-01 Self-injury 0.97
2020-09-01 Aggression 0.65
2020-09-01 Elopement 0.00
2020-09-01 Self-injury 1.58
2020-10-01 Aggression 0.24
2020-10-01 Elopement 0.00
2020-10-01 Self-injury 0.75
2020-11-01 …Run Code Online (Sandbox Code Playgroud) 我有一个简单的程序,应该显示饼图,但每当我运行该程序时,它都会在 Chrome 上打开一个页面,并且只是继续加载而没有任何显示,有时它拒绝连接。我该如何解决这个问题?
PS:我想离线使用它,我在windows10上使用cmd运行它
import pandas as pd
import numpy as np
from datetime import datetime
import plotly.express as px
def graph(dataframe):
figure0 = px.pie(dataframe, values=dataframe['POPULATION'], names=dataframe['CONTINENT'])
figure0.show()
df = pd.DataFrame({'POPULATION': [60, 17, 9, 13, 1], 'CONTINENT': ['Asia', 'Africa', 'Europe', 'Americas', 'Oceania']})
graph(df)
Run Code Online (Sandbox Code Playgroud) 我有2个csv文件,我的代码如下。
df = pd.read_csv("test.csv",
sep='\t',skiprows=range(9),names=['A', 'B', 'C','D'])
df2 = pd.read_csv("LoadMatch_Limit.csv",skiprows=range(1),names=['X','Y'])
fig = px.line([df,df2], x=['A','X'] , y=['D','Y'])
Run Code Online (Sandbox Code Playgroud)
我想要我的折线图,x 轴取自(“A”和“X”列),y 轴取自(“D”和“Y”列)。无论如何,我可以将这两张图表绘制为一张图吗?
作为一个简单的示例,我使用Plotly 2D Histograms网页上显示的第一个热图。该文档引用了hover_data参数,但我无法显示其他数据。示例中的数据框包括以下列:
>>> df.columns
Index(['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size'], dtype='object')
Run Code Online (Sandbox Code Playgroud)
根据上述文档,可以像这样添加悬停数据,例如“大小”:
>>> fig = px.density_heatmap(df, x="total_bill", y="tip", hover_data=['size'])
>>> fig.show()
Run Code Online (Sandbox Code Playgroud)
但是,生成的绘图仅显示悬停数据中的“total_bill”、“tip”和“count”。我缺少什么?
我有一个动画绘图散点图,它通常在 0-0.5 范围内绘制 x,y 坐标,日期/时间是帧关键。然而有时我将不得不处理异常数据点,这些数据点将远远超出这个范围。我希望图表能够动态缩放,以便点不会在屏幕外丢失。这可能吗?
def draw(x1,y1,timestamp):
d = {
"x1": x1_trim,
"y1": y1_trim,
"time": time_trim
}
df = pd.DataFrame(d)
fig = px.scatter(df, x="x1", y="y1", animation_frame="time")
fig.update_yaxes(autorange=True)
fig.update_xaxes(autorange=True)
fig.show()
Run Code Online (Sandbox Code Playgroud)
我尝试过将 update_x/yaxes 与自动范围一起使用,但它似乎不起作用。
我想在 3D 图中的两点之间画一条线。但是,由于文档中建议的某些原因,我无法使用plotly.express。https://plotly.com/python/3d-line-plots/
是否可以使用plotly.graph_objects模块在3D图中画一条线?如果是这样,怎么办?
我想向我的线图添加许多带有箭头的注释。但是,我不想手动添加它们(就像我在下面的代码中所做的那样)。这将是一项艰巨的工作,我宁愿直接从 df['text'] 列(或本列中的列表)添加注释。
import plotly.express as px
import pandas as pd
# assign data of lists.
data = {'x': [0, 1, 2, 3, 4, 5, 6, 7, 8],
'y': [0, 1, 3, 2, 4, 3, 4, 6, 5],
'text':["","","Annotation1","","Annotation2","","","",""]}
# Create DataFrame
df = pd.DataFrame(data)
fig = px.line(df, x='x', y='y', title='I want to add annotation with the tekst column in my dataframe (instead of manually)')
fig.add_annotation(x=2, y=3,
text="Annotation1 (added manual)",
showarrow=True,
arrowhead= 2)
fig.add_annotation(x=4, y=4,
text="Annotation2 (added manual)",
showarrow=True,
arrowhead= …Run Code Online (Sandbox Code Playgroud) plotly ×10
python ×8
pandas ×2
python-3.x ×2
annotations ×1
graph ×1
plot ×1
plotly-dash ×1
trendline ×1