问题:
这篇文章说明了如何更改要在Spyder下运行的Python安装Tools > Preferences > Python Interpreter。选项之一是Default (i.e. same as Spyder's):
但是,您如何找出那是什么呢?
一些细节:
我正在尝试帮助同事使用批处理文件运行Python脚本。该脚本可以从Spyder正常运行。但是,当我设置批处理文件时,出现了错误error importing module Seaborn。因此,我显然可以通过批处理设置运行Python(我在系统上找到的唯一python.exe),但是导入错误使我认为系统上还有更多无法安装的Python安装检测出于某种原因,但是是因为同样的剧本正在使用的Spyder不会引发同样的错误从Spyder的运行时。我在这里有点困惑,所以谢谢你的任何建议!
我有一个来自数据框的条形图:
fig = df.iplot(asFigure=True, kind='bar', barmode = 'relative')
py.iplot(fig)
Run Code Online (Sandbox Code Playgroud)
是否可以将数据框中的一列转换为线系列?
我正在尝试使用 python 中的 Plotly 绘制累积直方图,但使其看起来像“步骤”,即没有颜色且仅显示顶线的条形图。像这样的东西:
基本上,我试图重现以下 matplotlib 代码的行为:
import matplotlib.pyplot as plt
plt.hist(x, cumulative=True, histtype='step')
Run Code Online (Sandbox Code Playgroud)
到目前为止,我能做的最好的事情是:
import plotly.graph_objs as go
from plotly.offline import iplot
h = go.Histogram(x=x,
cumulative=dict(enabled=True),
marker=dict(color="rgba(0,0,0,0)",
line=dict(color="red", width=1)))
iplot([h])
Run Code Online (Sandbox Code Playgroud)
那么有什么技巧呢?
使用注释时,我尝试在绘图中为文本添加下划线。我使用添加注释
import plotly.graph_objects as go
g = go.FigureWidget(make_subplots(rows=1,cols=1))
g.update_layout(annotations=[dict(text='my text')]) #plus any other parameters
Run Code Online (Sandbox Code Playgroud)
是否有一个选项(也许在注释字典中?)带有下划线的文本?
谢谢!
我有一个数据框,df,列 pm1 和 pm25。我想显示这两个信号的相关性的图表(使用 Plotly)。到目前为止,我已经设法显示了散点图,但我没有设法绘制信号之间的相关性拟合线。到目前为止,我已经尝试过这个:
denominator=df.pm1**2-df.pm1.mean()*df.pm1.sum()
print('denominator',denominator)
m=(df.pm1.dot(df.pm25)-df.pm25.mean()*df.pm1.sum())/denominator
b=(df.pm25.mean()*df.pm1.dot(df.pm1)-df.pm1.mean()*df.pm1.dot(df.pm25))/denominator
y_pred=m*df.pm1+b
lineOfBestFit = go.Scattergl(
x=df.pm1,
y=y_pred,
name='Line of best fit',
line=dict(
color='red',
)
)
data = [dataPoints, lineOfBestFit]
figure = go.Figure(data=data)
figure.show()
Run Code Online (Sandbox Code Playgroud)
阴谋:
如何使 lineOfBestFit 正确绘制?
我已经在 plotly 上做了这个图
我想删除空白,只显示有值的 x,并隐藏没有任何值的 x
我该怎么做?
这是我的代码:
go.Bar(name=i,x=listeDepartement,y=listePPA))
fig = go.Figure(data=bar)
fig.update_layout(barmode='stack')
fig.write_html('histogram.html',auto_open=True)
fig.show()
Run Code Online (Sandbox Code Playgroud) 假设我有一个以下形式的嵌套字典:
{'geo': {'bgcolor': 'white','lakecolor': 'white','caxis': {'gridcolor': 'white', 'linecolor': 'white',}},
'title': {'x': 0.05},
'yaxis': {'automargin': True,'linecolor': 'white','zerolinecolor': 'white','zerolinewidth': 2}
}
Run Code Online (Sandbox Code Playgroud)
您如何通过该 dict 工作并列出包含该值的每个完整键路径'white'?使用用户 jfs 在帖子中定义的函数在嵌套字典中搜索值 python可以检查是否'white'至少出现一次并返回路径:
# dictionary
d={'geo': {'bgcolor': 'white','lakecolor': 'white','caxis': {'gridcolor': 'white', 'linecolor': 'white',}},
'title': {'x': 0.05},
'yaxis': {'automargin': True,'linecolor': 'white','ticks': '','zerolinecolor': 'white','zerolinewidth': 2}
}
# function:
def getpath(nested_dict, value, prepath=()):
for k, v in nested_dict.items():
path = prepath + (k,)
if v == value: # found value
return path
elif hasattr(v, 'items'): …Run Code Online (Sandbox Code Playgroud) 默认情况下,Plotly 在图例部分中单击其标签时隐藏该线。是否有任何其他键的组合shift/ctrl/alt/可以仅显示选定的行并隐藏所有其他行?
我正在使用以下代码使用 plotly express line 显示时间序列数据。
fig = px.line(df, x="date", y="close", color="type" ,category_orders = co ,color_discrete_sequence = colors,
line_group="type", title = company)
fig.update_layout(height=500, width=1500)#hovermode="x unified"
fig.show()
Run Code Online (Sandbox Code Playgroud)
但是在悬停时的绘图中,它以以下格式显示日期:“月,年”,即它不显示日期。但我希望以以下格式显示日期:“月日,年”。
正如您从屏幕截图中看到的,网格线直接从框的中间开始。
有什么办法可以用情节来做到这一点吗?

这是热图的设置:
colorscale= [[0, 'yellow'], [0.7, 'red'], [1, 'darkred']]
trace_activity = go.Heatmap(
z=activity_orgname['activity'],
x=activity_orgname['month'],
y=activity_orgname['org_name'].astype(str),
hoverongaps = False,colorscale=colorscale)
layout = go.Layout(title='Activity "' + ac_name + '" per Month:',
xaxis={'type':'category', "gridcolor": "rgba(157, 166, 0, 1)"},
yaxis={'type':'category', "gridcolor": "rgba(157, 166, 0, 1)"},
plot_bgcolor="white")
fig = go.Figure(data=[trace_activity],
layout=layout,
)
iplot(fig)
Run Code Online (Sandbox Code Playgroud) python ×10
plotly ×8
axis ×1
dataframe ×1
diagram ×1
dictionary ×1
formatting ×1
ggplotly ×1
heatmap ×1
histogram ×1
pandas ×1
regression ×1
spyder ×1
text ×1
underline ×1