我有一个 3D 散点图,我想更新图形的数据(移动滑块时)而不更改 3D 视图。
即使使用此解决方案,3D 视图也会重置:
@app.callback(Output('graph', 'figure'),
Input('slider', 'value'),
State('graph', 'figure'))
def update_fig(value, figure):
if value is not None:
data = new_data(value)
figure['data'][0]['x'] = data['x']
figure['data'][0]['y'] = data['y']
figure['data'][0]['z'] = data['z']
return figure
else:
return figure
Run Code Online (Sandbox Code Playgroud)
是否可以只更新点的坐标?
当我开始修改此处找到的分类气泡图示例时,图例中标记的大小变得非常小,以至于无法看到。
有没有办法在不改变图中标记大小的情况下控制图例标记大小?
我正在尝试在交互式绘图上绘制时间序列数据,以便我可以放大数据以进行详细观察。我的基本情节的主要代码是,
using IterableTables, DataFrames, CSV, Dates, TimeSeries, Plots
myfile="test2.csv"
dmft = dateformat"d/m/yyyy HH:MM:SS"
println(dmft)
df = DataFrame(CSV.File(joinpath(@__DIR__,myfile); dateformat=dmft))
df2 = filter(row -> row[:Date] <= Dates.DateTime("2020-10-15T00:06:00"), df)
x = convert(Matrix, df[:, [:Date]])
y = convert(Matrix, df[:, [:Col3]])
Run Code Online (Sandbox Code Playgroud)
#我放置了常用的绘图函数,我已为此块删除了该函数`
请有人建议我如何在交互式绘图上绘制这两列?
先感谢您。
我希望我的等高线图网格引用相同的颜色条,但我得到了四个堆叠的颜色条。我怎样才能只有一个颜色条,其数值引用所有图中的数据?或者,换句话说,我的绘图颜色如何引用相同的颜色条?
这是测试代码:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
z1 = [[2, 4, 7, 12, 13, 14, 15, 16],
[3, 1, 6, 11, 12, 13, 16, 17],
[4, 2, 7, 7, 11, 14, 17, 18],
[5, 3, 8, 8, 13, 15, 18, 19],
[7, 4, 10, 9, 16, 18, 20, 19],
[9, 10, 5, 27, 23, 21, 21, 21],
[11, 14, 17, 26, 25, 24, 23, 22]]
z2 = [[20, 44, 7, 120, 1, 1, 5, 16],
[3, 10, …Run Code Online (Sandbox Code Playgroud) 我想更改plotly python 中3D 曲面图的配色方案。Plotly 默认分配配色方案,如下图所示。
这是我的代码
import import plotly.graph_objects as go
import pandas as pd
data = pd.read_csv('\Data.csv')
data.set_index("years", inplace = True)
figure = go.Figure(data=[go.Surface(z=data.values)])
figure.update_layout(
scene = dict(
xaxis = dict(
title = 'Months',
#nticks = 5,
autorange='reversed',
showgrid=True,
gridwidth=1,
gridcolor='Blue',
ticktext = data.columns,
tickvals= list(range(0,data.shape[1]))),
yaxis = dict(
title = 'years',
showgrid=True,
gridwidth=1,
gridcolor='Blue',
ticktext = data.index,
tickvals= list(range(0,data.shape[0]))),
zaxis = dict(
title = 'Discharge (Cumecs)',
#showgrid=True,
gridwidth=1,
gridcolor='Blue')),
tilte = 'Plot 1'
)
Run Code Online (Sandbox Code Playgroud) 好的,所以我最初的想法是在绘图中绘制一个线图,并在特定阈值 t 之后用一种颜色为线着色,在阈值之前用另一种颜色为线着色。它适用于 23 或更少的点,但它适用于更多点,使用以下方法:
import numpy as np
import plotly.graph_objects as go
X = [j for j in range(0, 100)]
Y = [j for j in range(100000, 200000, 1000)]
X = X[:23]
Y = Y[:23]
X = np.array(X)
Y = np.array(Y)
t = 4
x = X[X <= t] # Include the threshold
y = Y[X <= t]
bx = X[X >= t]
by = Y[X >= t]
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y, line=dict(width=4, color='grey'), name="useless data"))
fig.add_trace(go.Scatter(x=bx, y=by, …Run Code Online (Sandbox Code Playgroud) 我想通过绘图制作类似于以下示例的动画条形图:https://plotly.com/python/animations/
我有以下代码:
fig = px.bar(
eu_vaccine_df.sort_values('date'),
x='country', y='people_vaccinated_per_hundred',
color='country',
animation_frame='date',
animation_group='country',
hover_name='country',
range_y=[0,50],
range_x=[0,30]
)
fig.update_layout(
template='plotly_dark',
margin=dict(r=10, t=25, b=40, l=60)
)
fig.show()
Run Code Online (Sandbox Code Playgroud)
我相信这个问题与我的数据框的“日期”列有关。目前它是一个日期时间,并已使用 pd.to_datetime(covid_df['date'] 进行转换
我得到的错误如下:
ValueError Traceback (most recent call last)
<ipython-input-185-ff9c8cc72d87> in <module>
7 hover_name='country',
8 range_y=[0,50],
----> 9 range_x=[0,30]
10 )
11 fig.update_layout(
/opt/conda/lib/python3.7/site-packages/plotly/express/_chart_types.py in bar(data_frame, x, y, color, facet_row, facet_col, facet_col_wrap, facet_row_spacing, facet_col_spacing, hover_name, hover_data, custom_data, text, base, error_x, error_x_minus, error_y, error_y_minus, animation_frame, animation_group, category_orders, labels, color_discrete_sequence, color_discrete_map, color_continuous_scale, range_color, color_continuous_midpoint, opacity, orientation, barmode, …Run Code Online (Sandbox Code Playgroud) 我正在学习plotly某人的代码,但是每次当我尝试运行特定代码来查看目标列以查看数据集的平衡程度时,都会弹出错误消息,并且会话会被中断。
弹出错误信息:
加载笔记本时发生错误:未捕获错误:“plotly”的脚本错误http://requirejs.org/docs/errors.html#scripterror
给我错误的代码
fig = px.histogram(
train_df,
x=target_column,
color=target_column,
color_discrete_sequence=px.colors.qualitative.G10,
)
fig.update_layout(
title_text='Target distribution', # title of plot
xaxis_title_text='Value', # xaxis label
yaxis_title_text='Count', # yaxis label
bargap=0.2, # gap between bars of adjacent location coordinates
paper_bgcolor=primary_bgcolor,
plot_bgcolor=primary_bgcolor,
)
fig.update_xaxes(
title='Target class',
categoryorder='category ascending',
)
fig.show()
Run Code Online (Sandbox Code Playgroud)
访问文档后,我了解到这是与浏览器相关的错误,但我不明白如何防止它。我正在使用chrome浏览器和kaggle内核。
https://plotly.com/python/strip-charts/中的第二个示例显示添加颜色(参见下面的屏幕截图),但这也会自动在红色和蓝色点之间创建间距。
我该如何关闭它?如何确保我的点为分类变量着色,而不制作两个单独的“条带”?
我将react-plotly.js与打字稿一起使用,并从中得到以下错误:
No overload matches this call.
Overload 1 of 2, '(props: PlotParams | Readonly<PlotParams>): Plot', gave the following error.
Type '({ type: string; mode: string; x: number[]; y: number[]; marker: { color: string; }; } | { type: string; x: number[]; y: number[]; mode?: undefined; marker?: undefined; })[]' is not assignable to type 'Data[]'.
Type '{ type: string; mode: string; x: number[]; y: number[]; marker: { color: string; }; } | { type: string; x: number[]; y: number[]; mode?: undefined; …Run Code Online (Sandbox Code Playgroud) plotly ×10
python ×6
plot ×2
colorbar ×1
contour ×1
interactive ×1
julia ×1
kaggle ×1
plotly-dash ×1
python-3.x ×1
reactjs ×1
strip ×1