在这张图中,两者之间差距太大了。另一方面,plotly sample code的间隙较小。我们如何才能做到这一点?
我的代码
plotly sample code
我的代码
import plotly.graph_objects as go
import plotly.express as px
import pandas as pd
data = {'one': [0.517970, 0.335520, 0.179993, 0.049795, -0.056827],
'two': [0.457973, 0.283992, 0.136433, 0.013717, -0.085876]}
df = pd.DataFrame(data)
fig = go.Figure()
fig.add_trace(go.Violin(x=df['one'],
name='one',
meanline_visible=True,
side='positive',
opacity=1))
fig.add_trace(go.Violin(x=df['two'],
name='two',
meanline_visible=True,
side='positive',
opacity=1))
fig.show()
绘图示例代码
import plotly.graph_objects as go
from plotly.colors import n_colors
import numpy as np
np.random.seed(1)
# 12 sets of normal distributed random data, with increasing mean and standard deviation
data = (np.linspace(1, 2, 12)[:, np.newaxis] * np.random.randn(12, 200) +
(np.arange(12) + 2 * np.random.random(12))[:, np.newaxis])
colors = n_colors('rgb(5, 200, 200)', 'rgb(200, 10, 10)', 12, colortype='rgb')
fig = go.Figure()
for data_line, color in zip(data, colors):
fig.add_trace(go.Violin(x=data_line, line_color=color))
fig.update_traces(orientation='h', side='positive', width=3, points=False)
fig.update_layout(xaxis_showgrid=False, xaxis_zeroline=False)
fig.show()
1条答案
按热度按时间46qrfjad1#
您可以通过调整轨迹的
width
属性来获得类似于文档中示例的结果,例如:绘图
完整代码