我正在绘制一个水平堆积条形图,我希望 x 轴上的每个项目都反映一个日期时间值而不是一个整数。我正在绘制以秒为单位的值。如何更改 x 轴刻度标签以反映日期时间?谢谢!
import plotly.plotly as plt
import plotly.graph_objs as gph
data = [
('task 1', 300),
('task 2', 1200),
('task 3', 500)
]
traces = []
for (key, val) in data:
traces += [gph.Bar(
x=val,
y=1,
name=key,
orientation='h',
)]
layout = gph.Layout(barmode='stack')
fig = gph.Figure(data=traces, layout=layout)
plt.iplot(fig)
Run Code Online (Sandbox Code Playgroud) 我试图在没有 Input 的情况下调用 plotly-dash 回调,并且该方法不会触发。
这是我尝试使用破折号构建的仪表板。过去,当我对 Input 和 Output 使用回调时,一切正常,但是当我尝试仅使用 output 时,结果不会显示在仪表板上。
html.Div(
[
html.P(
"Tweet Count",
className="twelve columns indicator_text"
),
html.P(
id = 'tweet_value',
className="indicator_value"
),
],
className="four columns indicator",
)
@app.callback(
Output("tweet_value","children")
)
def total_tweet_callback():
return 100
Run Code Online (Sandbox Code Playgroud) 我有以下内容,使用 plotly express:
fig = px.line(series1, x='timestamp', y='data')
fig.show()
Run Code Online (Sandbox Code Playgroud)
它工作正常。
我想一起制作多个图,所以我做了:
fig = make_subplots(rows=2, cols=1)
fig.add_trace(px.line(series1, x='timestamp', y='data'), row=1, col=1)
fig.add_trace(px.line(series2, x='timestamp', y='data'), row=1, col=1)
fig.add_trace(px.line(series2, x='timestamp', y='data'), row=2, col=1)
fig.show()
Run Code Online (Sandbox Code Playgroud)
但我得到:
为无效元素的 'data' 属性接收到的无效元素包括:[Figure({ 'data': [{'hoverlabel': {'namelength': 0},
虽然,
fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Scatter(x=series1['timestamp'], y=series1['data']), row=1, col=1)
fig.add_trace(go.Scatter(x=series2['timestamp'], y=series2['data']), row=1, col=1)
fig.add_trace(go.Scatter(x=series2['timestamp'], y=series2['data']), row=1, col=2)
fig.show()
Run Code Online (Sandbox Code Playgroud)
将工作; 所以看起来 plotly express 不适用于子图。
我错过了什么吗?
另外,作为一个额外的问题:我还没有找到如何为每个跟踪指定颜色。
我!pip install chart_studio在 jupyter notebook 中运行。
然后在运行此代码时:
import numpy as np
import pandas as pd
import cufflinks as cf
import chart_studio.plotly as py
from chart_studio.plotly import iplot
import plotly.graph_objects as go
chart_studio.tools.set_credentials_file(username=xx, api_key = xxx)
Run Code Online (Sandbox Code Playgroud)
我回来了:
No module named 'chart_studio'
我尝试过语法更正,但没有任何乐趣。有什么建议?
我正在尝试为我的每个跟踪绘制一个选定的标记。我想为标记和线条分配相同的颜色。有没有办法获得我的痕迹的颜色属性?
fig = go.Figure()
fig.add_trace(go.Scatter(
x=[0, 1, 2, 3, 4, 5],
y=[0, 3, 5, 7, 9, 11],
name='trace01',
mode='lines+markers',
marker=dict(size=[0, 0, 30, 0, 0, 0],
color=[0, 0, 10, 0, 0, 0])
))
fig.add_trace(go.Scatter(
x=[0, 1, 2, 3, 4, 5],
y=[3, 5, 7, 9, 11, 13],
name='trace02',
mode='lines+markers',
marker=dict(size=[0, 0, 0, 30, 0, 0],
color=[0, 0, 0, 10, 0, 0])
))
fig.show()
Run Code Online (Sandbox Code Playgroud)
我想在 plotly dash 中绘制一个带有两个子图的图表。我的整个图表如下所示:
import pandas as pd
import numpy as np
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from plotly.subplots import make_subplots
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv').iloc[:60]
fig = make_subplots(rows=2, cols=1, row_heights=[0.8, 0.2], vertical_spacing=0)
fig.add_trace(go.Candlestick(open=df['AAPL.Open'], high=df['AAPL.High'], low=df['AAPL.Low'], close=df['AAPL.Close'],
increasing_line_color='#0384fc', decreasing_line_color='#e8482c', name='AAPL'), row=1, col=1)
fig.add_trace(go.Scatter(y=np.random.randint(20, 40, len(df)), marker_color='#fae823', name='VO', hovertemplate=[]), row=2, col=1)
fig.update_layout({'plot_bgcolor': "#21201f", 'paper_bgcolor': "#21201f", 'legend_orientation': "h"},
legend=dict(y=1, x=0),
font=dict(color='#dedddc'), dragmode='pan', hovermode='x unified',
margin=dict(b=20, t=0, l=0, r=40))
fig.update_xaxes(showgrid=False, zeroline=False, rangeslider_visible=False, showticklabels=False,
showspikes=True, spikemode='across', spikesnap='data', …Run Code Online (Sandbox Code Playgroud) https://plotly.com/python/line-and-scatter/有许多散点图示例,但没有一个向您展示如何在 px.scatter 中设置所有点的颜色:
# x and y given as DataFrame columns
import plotly.express as px
df = px.data.iris() # iris is a pandas DataFrame
fig = px.scatter(df, x="sepal_width", y="sepal_length")
fig.show()
Run Code Online (Sandbox Code Playgroud)
我试过添加colour = 'red'等不起作用。这些示例仅向您展示如何通过其他变量着色。
原则上我可以添加另一个功能并将其设置为相同,但这似乎是完成任务的一种奇怪的方式......
我想仅在单击按钮后才使用 plotly 显示图形,但我不确定如何进行此操作。我的图存储在以下代码位中
fig1 = go.Figure(data=plot_data, layout=plot_layout)
Run Code Online (Sandbox Code Playgroud)
然后我使用以下代码位定义我的应用程序布局:
app.layout = html.Div([
#button
html.Div(className='submit', children=[
html.Button('Forecast', id='submit', n_clicks=0)
]),
#loading
dcc.Loading(
id="loading-1",
type="default",
children=html.Div(id="loading-output-1")
),
#graph
dcc.Graph(id= 'mpg-scatter',figure=fig),
#hoverdata
html.Div([
dcc.Markdown(id='hoverdata-text')
],style={'width':'50%','display':'inline-block'})
])
@app.callback(Output('hoverdata-text','children'),
[Input('mpg-scatter','hoverData')])
def callback_stats(hoverData):
return str(hoverData)
if __name__ == '__main__':
app.run_server()
Run Code Online (Sandbox Code Playgroud)
但问题是我只想首先显示按钮。然后当有人点击预测按钮时,加载功能出现,一秒钟后图表显示。我定义了一个 dcc.loading 组件,但不确定如何定义此功能的回调。
有没有办法在 3-D 等距视图中制作一个 z-stack 2-D 图像,每个 2-D 图像中的点向下投影到下一个 2-D 图像切片?我确信这有一个技术术语,但我只是没有词汇来找到最相关的答案。有人能指出我正确的方向吗?
下面,我已经绘制了一个关于它是什么样子的“想法”。我很想知道这是否可行,而无需为matplotlib其他 Python 绘图库重新发明轮子。
我试图在 Visual Studio Code 中打印一个情节图并发现了这个错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-40-e07b5feb5ded> in <module>
30
31 fig.update_layout(height=nrows*500)
---> 32 fig.show()
C:\Python38\lib\site-packages\plotly\basedatatypes.py in show(self, *args, **kwargs)
3147 import plotly.io as pio
3148
-> 3149 return pio.show(self, *args, **kwargs)
3150
3151 def to_json(self, *args, **kwargs):
C:\Python38\lib\site-packages\plotly\io\_renderers.py in show(fig, renderer, validate, **kwargs)
383
384 if not nbformat or LooseVersion(nbformat.__version__) < LooseVersion("4.2.0"):
--> 385 raise ValueError(
386 "Mime type rendering requires nbformat>=4.2.0 but it is not installed"
387 )
ValueError: Mime type rendering …Run Code Online (Sandbox Code Playgroud) plotly ×10
python ×9
plotly-dash ×3
colors ×1
matplotlib ×1
nbformat ×1
pandas ×1
pip ×1
seaborn ×1