如何更改次xaxis标签的大小或旋转,使其在作为静态图像导出时不会与线条重叠
# packages
import pandas as pd
import plotly.graph_objects as go
df_RampUp_2030 = pd.read_excel('RampUp.xlsx', index_col=[0,1])
# define xlabels
xlabels = [list(df_RampUp_2030.index.get_level_values(0)),
list(df_RampUp_2030.index.get_level_values(1)),
df_RampUp_2030.index]
fig = go.Figure()
# create traces
for idx, tech in enumerate(df_RampUp_2030.columns):
fig.add_trace(
go.Bar(
y=df_RampUp_2030[tech],
x=xlabels,
name=tech,
showlegend=True,
width=0.5,
)
)
# specify layout
fig.update_layout(
yaxis=dict(
titlefont_size=16,
tickfont_size=12,
title="Mio. Stk.",
showspikes=True),
xaxis=dict(
titlefont_size=16,
tickfont_size=12),
title_text='Fahrzeughochlauf<br>alternativer Antriebstechnologien bis 2030',
template='plotly_white',
barmode='stack',
)
fig.show()
在生成的图像中,标签NPE 2018和eMobil 2050不适合给定的空间。是否可以仅旋转这两个标签?如果没有,如何更改辅助标签的字体大小
数据:
+-----------------+-------------------+-------+-------+-------+------+------------------+
| Studie | Szenario | BEV | PHEV | FCV | REEV | Elektrofahrzeuge |
+-----------------+-------------------+-------+-------+-------+------+------------------+
| dena | RF | 1.9 | 3.2 | 0.9 | | |
| dena | TM | 5.6 | 16.4 | 2.2 | | |
| dena | EL | 13.3 | 11.0 | 1.2 | | |
| BCG | RF | 2.0 | 7.0 | 0.0 | | |
| BCG | 80 | 4.0 | 6.0 | 0.0 | | |
| BCG | 95 | 4.0 | 6.0 | 0.0 | | |
| NPE 2018 | konservativ | | | | | 4.2 |
| NPE 2018 | optimistisch | | | | | 7.0 |
| RENEWBILITY III | Basis | 0.449 | 2.513 | 0.004 | | |
| RENEWBILITY III | Fokus Kraftstoffe | 0.456 | 2.55 | 0.0 | | |
| RENEWBILITY III | Pkw-Maut | 1.004 | 6.277 | 0.007 | | |
| RENEWBILITY III | ohne O-LKW | 1.037 | 6.485 | 0.0 | | |
| RENEWBILITY III | Effizienz Plus | 1.037 | 6.485 | 0.008 | | |
| RENEWBILITY III | Effizienz | 1.001 | 5.387 | 0.008 | | |
| eMobil 2050 | Regional eMobil | 3.0 | 1.0 | | 2.0 | |
| eMobil 2050 | Grenzenlos eMobil | 2.0 | 2.0 | | 2.0 | |
+-----------------+-------------------+-------+-------+-------+------+------------------+
我修正了两点。首先,我将图例移到标题顶部,以便在右侧为其腾出空间。接下来,我通过手动设置图像大小而不是自动设置来增加宽度
相关问题 更多 >
编程相关推荐