python - 如何正确设置格子图的 y 轴,使其不被弄脏?
问题描述
我正在尝试为数据集制作格子图,但无法使其正常工作。该情节适用于带有适当空格的fig.show()的 Jupiter 笔记本。但不知何故,我需要设置渲染器以在 Spyder 4 中查看图形。我需要在 spyder 4 中生成绘图并在后面保存它。保存部分很容易。
import plotly.express as px
fig = px.bar(df, x='Shooter Race', y='Total Number of Fatalities',
labels={
"Total Number of Victims": "Victims",
"Total Number of Fatalities": "Fatalities",
"Shooter Race":'Race',
},
width=None,
facet_col='binned', facet_col_wrap=2)
fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1])) # removing the facet_col col name
fig.update_layout(
autosize=False,
width=800,
height=800,)
fig.show(renderer='png') # I need to save it in .png
我的输出
我尝试了如下无花果更新参数但仍然没有运气
fig.update_layout(
autosize=False,
width=800,
height=800,)
解决方案
移除
fig.show(renderer='png')
并替换为
fig.show()
fig.write_image("fig1.png")
以某种方式解决了这个问题。但我不确定这个奇怪问题背后的逻辑是什么,我想知道这个谢谢。
推荐阅读
- docker - 如何对多个容器运行单个 docker exec 命令
- anylogic - 在旧版本中打开 Anylogic 模型
- reactjs - 如何在组件覆盖的帮助下在材料表中添加列?
- database - 我需要分类单词的词汇数据库
- laravel - 使用 Socialite 对 laravel 5.4 进行身份验证时,Google Auth 登录个人资料的名字和姓氏为空
- java - 无法确定类型:org.json.JSONObject,表:ordersinfo,列:[org.hibernate.mapping.Column(items)]
- reactjs - React 类型文件在 React TypeScript (.tsx) 文件中不起作用 - 为 React 组件引发 ESLint 错误
- node.js - 使用 Checkout 在 Stripe 中的发票上显示增值税
- python - 无法连接无法公开访问的 redshift 集群
- angularjs - 是否有针对 angularjs 的 apollo 客户端的任何文档?我搜索了整个互联网,但我只能看到 Angular2+ 文档