有人可以帮助我调整在 Jupyter 中使用plotly 生成的 HTML 文件的大小吗?这是我用来保存到 HTML 文件的代码:
fig.write_html("D:\jupyter\image.html")
Run Code Online (Sandbox Code Playgroud)
它有效,但现在我想控制大小。这里(https://plotly.com/python/interactive-html-export/)建议如何做到这一点,但我无法理解如何具体编写代码以避免获得大图像
我想使用plotly从某些图中的x轴中删除某些间隔。我从https://plotly.com/python/time-series/找到了附加的示例。但运行它给了我错误
ValueError:为plotly.graph_objs.layout.XAxis类型的对象指定无效属性:'rangebreaks'
我什至升级了我的情节版本。如何使用 rangebreaks 属性?
import plotly.express as px
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
fig = px.scatter(df, x='Date', y='AAPL.High', range_x=['2015-12-01', '2016-01-15'],
title="Hide Gaps with rangebreaks")
fig.update_xaxes(
rangebreaks=[
dict(bounds=["sat", "mon"]), #hide weekends
dict(values=["2015-12-25", "2016-01-01"]) # hide Christmas and New Year's
]
)
fig.show()
Run Code Online (Sandbox Code Playgroud) 我一直在努力解决这个看似简单的任务:如何将两个 x 轴与相关数据对齐。就我而言,一个轴以摄氏度为单位,另一个轴以华氏度为单位。
\n\n我想要实现的是获得两个 x 轴的对齐,以便:
\n\n32\xc2\xb0F = 0\xc2\xb0C \n并且\n50\xc2\xb0F = 10\xc2\xb0C
\n\n通过这种关系,两个数据集将在温度方面对齐。
\n\n我希望将两个单位集放在同一个图表上,以便查看者可以根据他们习惯的单位来解释数据。
\n\n这是我的代码:
\n\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\nfrom plotly.graph_objs.layout import YAxis,XAxis,Margin\n\nlayout = go.Layout(\n title="Double X Axis Example",\n xaxis=XAxis(\n title="Celcius"\n ),\n xaxis2 = XAxis(\n title="Fahrenheits",\n overlaying= \'x\', \n side= \'top\',\n ),\n yaxis=dict(\n title="Y values"\n ),\n)\n\n# Create figure with secondary x-axis\nfig = go.Figure(layout=layout)\n\n# Add traces\nfig.add_trace(\n go.Scatter(x=[10, 20, 30], y=[4.5, 6, 5], name="data set in celcius"),\n)\n\nfig.add_trace(\n go.Scatter(x=[40, 60, 80], y=[4, 5, 6.5], name="data …Run Code Online (Sandbox Code Playgroud) 注释掉的行是我最好的猜测。
def _make_json(self, given_panda: pd.DataFrame, sort_by: str) -> str:
figure = px.scatter_mapbox(given_panda,
hover_name='City',
hover_data=['State', 'Average_Low', 'Average_High', 'Latitude', 'Longitude', 'Record_Low', 'Record_High', 'Wind', 'Elevation', 'Humidity', 'Total_Precip'],
color=sort_by,
color_continuous_scale=px.colors.sequential.Plasma,
zoom=3.4,
opacity=1,
lat='Latitude',
lon='Longitude',
center={'lat': 37.0902, 'lon': -95.7129},
mapbox_style='carto-darkmatter')
figure.update_layout(margin = {'r':0,'t':0,'l':0,'b':0})
#figure.update(layout = dict(legend = dict(bgcolor = 'red')))
return figure.to_json()
Run Code Online (Sandbox Code Playgroud)
这是可能有用的东西 https://plotly.com/python/reference/#layout-showlegend
这是我的代码:
fig = px.choropleth_mapbox(district_df[['District','Confirmed','Deaths','id','province']], geojson = geo_df, locations='id', color='Confirmed',
color_continuous_scale="Viridis",
mapbox_style="carto-positron",
zoom=5.9, hover_name = 'District',hover_data = {'District':False, 'Confirmed':True,'Deaths':True,'province':False,'id':False},
opacity=0.5, center = {"lat": 28.3949, "lon": 84.1240})
Run Code Online (Sandbox Code Playgroud)
我想禁用缩放选项。有办法吗?
我有一个数据框df,其中包含随时间变化的值(过程数据)。我有一个数据框ef,其中包含具有开始时间和结束时间的事件(警报)。我想以一种美观的方式将它们组合在一个情节中。
"""
df==
+---------------------+------------+------------+------------+
| | processA | processB | processC |
|---------------------+------------+------------+------------|
| 2020-01-01 00:00:00 | 101.764 | 20.0079 | 0.978738 |
| 2020-01-01 00:01:00 | 102.241 | 93.3779 | -0.977278 |
| 2020-01-01 00:02:00 | 100.95 | -7.56786 | -0.103219 |
| 2020-01-01 00:03:00 | 100.411 | 7.20218 | 1.45427 |
| 2020-01-01 00:04:00 | 100.761 | 6.08375 | 0.443863 |
+---------------------+------------+------------+------------+
ef==
+----+-----------------------------------------+---------------------+---------------------+----------+
| | alm | Start | Finish | almid | …Run Code Online (Sandbox Code Playgroud) 我通常使用 Plotly 绘图并将它们保存为独立的 HTML 文件,这对于与同事共享和“冻结”正在显示的数据非常方便。这是我用的一个例子
\nplotly.offline.plot(\n plotly_plot, \n filename = \'standalone great plot.html\',\n)\nRun Code Online (Sandbox Code Playgroud)\n现在我想用一个非常简单的 Dash 应用程序做同样的事情,它根本没有服务器端要求,它只是一堆 Plotly 图形和一些文本。我怎样才能做到这一点?
\n考虑本教程中显示的第一个示例,为了方便起见,我将其复制粘贴到此处:
\n# -*- coding: utf-8 -*-\n\n# Run this app with `python app.py` and\n# visit http://127.0.0.1:8050/ in your web browser.\n\nimport dash\nimport dash_core_components as dcc\nimport dash_html_components as html\nimport plotly.express as px\nimport pandas as pd\n\nexternal_stylesheets = [\'https://codepen.io/chriddyp/pen/bWLwgP.css\']\n\napp = dash.Dash(__name__, external_stylesheets=external_stylesheets)\n\n# assume you have a "long-form" data frame\n# see https://plotly.com/python/px-arguments/ for more options\ndf = pd.DataFrame({\n "Fruit": …Run Code Online (Sandbox Code Playgroud) 我正在尝试在一个图中实现两个滑块我尝试了以下操作
# Create figure
fig = go.Figure()
# Add traces, one for each slider step
for step in np.arange(1, 5, 1):
fig.add_trace(
go.Scatter(
visible=False,
line=dict(color="#00CED1", width=6),
name=" = " + str(step),
x=np.arange(0, 10, 0.01),
y=[step]*50))
# Make 10th trace visible
fig.data[1].visible = True
# Create and add slider
sliders = []
for j in range(int(len(fig.data)/2)):
steps=[]
for i in range(int(len(fig.data)/2)):
step = dict(
method="update",
args=[{"visible": [False] * (int(len(fig.data)/2))},
{"title": "Slider switched to step: " + str(i)}], # layout attribute
) …Run Code Online (Sandbox Code Playgroud) 我很想知道是否有相当于:
import pandas as pd
import numpy as np
data = pd.DataFrame({'Day':range(10),
'Temperature': np.random.rand(10),
'Wind': np.random.rand(10),
'Humidity': np.random.rand(10),
'Pressure': np.random.rand(10)})
data.set_index('Day').plot(subplots=True, layout=(2,2), figsize=(10,5))
plt.tight_layout()
Run Code Online (Sandbox Code Playgroud)
这会生成 Plotly 图表,而不是 matplotlib 图表。
plotly ×10
python ×9
pandas ×2
plotly-dash ×2
choropleth ×1
html ×1
legend ×1
mapbox ×1
slider ×1