python - 将 x 轴格式化为 %,将 y 轴格式化为 £
问题描述
我在 Power BI 中使用了这个 python 代码:
colors = ["#FF0B04", "#ffbf00", "#228800"]
sns.set_palette(sns.color_palette(colors))
g = sns.JointGrid(data=dataset, x="Score", y="Profit", hue= 'Score Bands')
g.plot(sns.scatterplot, sns.histplot,legend=False)
plt.tight_layout()
plt.show()
任何人都可以帮助将 x 轴格式化为 % 并将 y 轴格式化为 £ 吗?
解决方案
使用来自官方网站的示例数据,我将 seaborn 与 ax 相关联,然后使用 formatter 以 unicode 指定百分比显示和欧元货币符号。
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
tips = sns.load_dataset("tips")
colors = ["#FF0B04", "#ffbf00", "#228800"]
sns.set_palette(sns.color_palette(colors))
g = sns.JointGrid(data=tips, x="total_bill", y="tip", hue= 'time')
g.plot(sns.scatterplot, sns.histplot,legend=False)
ax = g.ax_joint
ax.xaxis.set_major_formatter(ticker.PercentFormatter(xmax=5))
ax.yaxis.set_major_formatter(ticker.FormatStrFormatter("\u20ac%d"))
plt.tight_layout()
plt.show()
推荐阅读
- javascript - Asp.net MVC 中的三个表级联下拉列表
- javascript - Pusher.subscribe() 不是来自服务器端的函数?
- python - 像素/数组位置到 lat long gdal Python
- python - 使用强化学习预测价格
- java - 如果我在 try/catch 之后关闭数据库连接而不是 finally
- node.js - 如何使用 Electron 检查特定软件是否安装在系统上?
- java - cassandra java驱动程序连接抛出noHostAvailableException
- ios - 提高游戏速度并保持节点之间的距离相同
- c# - 在我的局域网上发布我在 Visual Studio 上制作的 asp.net 页面
- javascript - 从数组对象中获取特定值 ES6 方式