Matplotlib 3.0 Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

The following is the code block that draws violin plots: 

  1. Read the data from a CSV file into a pandas DataFrame:
wine_quality = pd.read_csv('winequality.csv', delimiter=';')

  1. Prepare the list of three attributes of wine_quality:
data = [wine_quality['alcohol'], wine_quality['fixed acidity'], 
wine_quality['quality']]
  1. Plot the violin plot:
plt.violinplot(data, showmeans=True)
  1. Display the plot on the screen:
plt.show()