python - 在绘图中从底部到图形留出空间
问题描述
我正在使用此代码在一个图中绘制两个图,但我不知道如何从底部给图形留出空间。
def visualize_trends(df, features, titles, fig_title, fn, vs = 0.18, h = 1000, w = 800):
trace0 = go.Scatter(
x = df[features[0]],
y = df['Past_Developers_Count'],
mode = 'lines+markers',
name = 'Past',
)
trace1 = go.Scatter(
x = df[features[1]],
y = df['Future_Developers_Count'],
mode = 'lines+markers',
name = 'Future',
)
fig = tools.make_subplots(rows = 2, cols = 1, vertical_spacing = vs, subplot_titles = titles)
fig.append_trace(trace0, 1, 1)
fig.append_trace(trace1, 2, 1)
fig['layout'].update(height = h, width = w, paper_bgcolor = 'rgb(233,233,233)', title = fig_title)
py.iplot(fig, filename = fn)
输出:
是否有任何参数可以提供空间,就像我vertical_spacing
以前在两个图表之间提供空间一样?
解决方案
I figured it out myself. You can give margin
to give required space. In margin
, you can specify space from all sides left, right, bottom, up
.
margin = dict(l = 10, r = 20, b = 30, u = 40)
You can pass values according to your own requirements. I did like this in my case to give space from bottom,
margin = dict(b = 140)
Complete function,
def visualize_trends(df, features, titles, fig_title, fn, vs = 0.18, h = 1000, w = 800):
trace0 = go.Scatter(
x = df[features[0]],
y = df['Past_Developers_Count'],
mode = 'lines+markers',
name = 'Past',
)
trace1 = go.Scatter(
x = df[features[1]],
y = df['Future_Developers_Count'],
mode = 'lines+markers',
name = 'Future',
)
fig = tools.make_subplots(rows = 2, cols = 1, vertical_spacing = vs, subplot_titles = titles)
fig.append_trace(trace0, 1, 1)
fig.append_trace(trace1, 2, 1)
fig['layout'].update(height = h, width = w, margin = dict(b = 140),
paper_bgcolor = 'rgb(233,233,233)', title = fig_title)
py.iplot(fig, filename = fn)
Output:
Note: I am posting this answer so someone can save their time on this issue.
推荐阅读
- google-cloud-platform - 谷歌云计算引擎的一个实例可以有多个外部 IP 地址吗
- python - 在 Pandas 中确定特定时间的最小值和最大值
- pointers - 指针的意外行为
- angular - Angular 8 - 如何在我的 Angular 项目中构建包含所有路由的动态菜单?
- flutter - 如何在 sqflite 数据库中加载数据?
- java - 我在春季使用 SOAP 的代码优先方法没有正确生成 XSD 和 WSDL
- php - 插入的值应该是 0 但它是空的
- python - 无法安装 Kivy。视窗 10
- android - 从没有 ID 的 Firebase 中删除记录
- angular - 在表单 Array Angular 8 中添加 2 个表单控件