J'essayais de parcourir la barillet de barbolive et de la même parcelle dans le même intrigue, mais cela ne montre que ScatterPlot.
Comment montrer à la fois les parcelles?
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib.ticker import PercentFormatter
import plotly
import plotly.offline as py
import plotly.graph_objs as go
import plotly.figure_factory as ff
import plotly.tools as tls
from plotly.subplots import make_subplots
from plotly.offline import plot, iplot, init_notebook_mode
init_notebook_mode(connected=False)
df = pd.DataFrame({
'price': [ 4.0, 17.0, 7.0, 7.0, 2.0, 1.0, 1.0],
'item': ['Apple', 'banana', 'carrot', 'Plum',
'orange', 'date', 'cherry']})
df = df.sort_values(num,ascending=False)
df['cumulative_sum'] = df[num].cumsum()
df['cumulative_perc'] = 100*df['cumulative_sum']/df[num].sum()
df['demarcation'] = 80
num = 'price'
cat = 'item'
title = 'Pareto Chart'
trace1 = go.Bar(
x=df[cat],
y=df[num],
name=num,
marker=dict(
color='rgb(34,163,192)'
)
)
trace2 = go.Scatter(
x=df[cat],
y=df['cumulative_perc'],
name='Cumulative Percentage',
yaxis='y2',
)
data = [trace1,trace2]
fig = dict(data=data)
iplot(fig)
plt.xticks(rotation=90)
Pour faire pivoter l'étiquette d'axe X.z-order
Pour spécifier l'ordre de dessin.import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({
'price': [ 4.0, 17.0, 7.0, 7.0, 2.0, 1.0, 1.0],
'item': ['Apple', 'banana', 'carrot', 'Plum',
'orange', 'date', 'cherry']})
num = 'price'
cat = 'item'
df = df.sort_values(num, ascending=False)
df['cumulative_sum'] = df[num].cumsum()
df['cumulative_perc'] = 100*df['cumulative_sum']/df[num].sum()
df['demarcation'] = 80
title = 'Pareto Chart'
plt.figure(figsize=(9, 3))
axes1 = plt.subplot()
b = axes1.bar(df[cat], df[num], label='Price')
plt.xticks(rotation=90)
# use twinx() function to create the second axis object “ax2”
axes2 = axes1.twinx()
p = axes2.plot(df[cat], df['cumulative_perc'], c='r', marker='o', zorder=5, label='Cumulative Percentage')
axes1.legend(handles=(b, p[0]), loc='center right')
plt.tight_layout()
plt.show()