反转轴方向 Altair

Yit*_*iti 5 python axis altair

由于某种原因,使用 Altair 绘图时的 Y 轴似乎是反转的(预计值从绘图的较低(底部)到较高(顶部))。另外,我希望能够更改滴答频率。对于旧版本,我可以使用ticks=n_ticks,但现在看来这个参数只能采用布尔值。

\n
import altair as alt\nalt.renderers.enable(\'notebook\')\n\neff_metals =  pd.read_excel(filename, sheet_name=\'summary_eff_metals\')\npoints = alt.Chart(eff_metals, height=250, width=400).mark_circle().encode(\n    x=alt.X(\'Temperature:Q\',axis=alt.Axis(title=\'Temperature (\xc2\xb0C)\'),\n            scale=alt.Scale(zero=False, padding=50)),\n    y=alt.Y(\'Efficiency:N\',axis=alt.Axis(title=\'Efficiency (%)\'),\n            scale=alt.Scale(zero=False, padding=1)),\n    color=alt.Color(\'Element:N\'),\n)\ntext = points.mark_text(align=\'right\', dx=0, dy=-5).encode(\n    text=\'Element:N\'\n)\nchart = alt.layer(points, text, data=eff_metals, \n                  width=600, height=300)\nchart\n
Run Code Online (Sandbox Code Playgroud)\n

以及图:\n在此输入图像描述

\n

Rob*_*inL 4

我没有你的数据,所以很难编写工作代码。

\n

但这里有一个带有附加刻度的倒置比例示例,类似于带有工具提示的散布示例。请参阅此处的 vega 编辑器。

\n
import altair as alt\nfrom vega_datasets import data\n    \niris = data.iris()\n    \nalt.Chart(iris).mark_point().encode(\n    x=\'petalWidth\',\n    y=alt.Y(\'petalLength\', scale=alt.Scale(domain=[7,0]), axis=alt.Axis(tickCount=100)),\n    color=\'species\'\n).interactive()\n
Run Code Online (Sandbox Code Playgroud)\n

这可能适用于您的数据:

\n
eff_metals =  pd.read_excel(filename, sheet_name=\'summary_eff_metals\')\npoints = alt.Chart(eff_metals, height=250, width=400).mark_circle().encode(\n    x=alt.X(\'Temperature:Q\',axis=alt.Axis(title=\'Temperature (\xc2\xb0C)\'),\n            scale=alt.Scale(zero=False, padding=50)),\n    y=alt.Y(\'Efficiency:N\',axis=alt.Axis(title=\'Efficiency (%)\'),\n            scale=alt.Scale(zero=False, padding=1, domain=[17,1])),\n    color=alt.Color(\'Element:N\'),\n)\ntext = points.mark_text(align=\'right\', dx=0, dy=-5).encode(\n    text=\'Element:N\'\n)\nchart = alt.layer(points, text, data=eff_metals, \n                  width=600, height=300)\nchart\n
Run Code Online (Sandbox Code Playgroud)\n

但是,我认为您的效率变量的类型可能错误。您可以尝试替换\'Efficiency:N\'为“效率:Q”,这样可以吗?

\n

  • 404 在 https://altair-viz.github.io/gallery/simple_scatter.html (2认同)