importmatplotlib.pyplotasplt# 创建柱状图plt.figure(figsize=(10,6))plt.bar(df['类别'],df['值'])plt.yscale('log')# 设置纵坐标为对数坐标plt.title('对数坐标的柱状图')plt.xlabel('类别')plt.ylabel('值 (对数尺度)')plt.grid(True,which="both",linestyle='--',linewidth=0.5)plt.show() 1....
使用pandas.DataFrame的plot方法绘制图像会按照数据的每一列绘制一条曲线,默认按照列columns的名称在适当的位置展示图例,比matplotlib绘制节省时间,且DataFrame格式的数据更规范,方便向量化及计算。 DataFrame.plot( )函数: DataFrame.plot(x=None, y=None, kind='line', ax=None, subplots=False, sharex=None, share...
3.2 使用dataframe的plot方法 使用dataframe的plot方法,并将方法中的kind='bar' 参数值。具体参考下面的第7节相关内容。 4. 饼图 4.1 使用dataframe的plot对象的pie方法 使用dataframe的plot对象的pie方法的示例代码如下: # -*- coding: utf-8 -*- import matplotlib import numpy as np import matplotlib.pyplot...
‘line’ : line plot (default)#折线图‘bar’ : vertical bar plot#条形图‘barh’ : horizontal bar plot#横向条形图‘hist’ : histogram#柱状图‘box’ : boxplot#箱线图‘kde’ : Kernel Density Estimation plot#Kernel 的密度估计图,主要对柱状图添加Kernel 概率密度线‘density’ : same as ‘kde’...
data : DataFrame, array, or list of arrays, optional #设置输入的数据集 Dataset for plotting. If x and y are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form. order, hue_order : lists of strings, optional #控制变量绘图的顺序 Order to plot the categori...
-'bar': 垂直条形图 -'barh': 水平条形图 -'hist': 直方图 -'box': 箱型图 -'kde': 核密度估计图 -'density':与'kde'相同 -'area': 面积图 -'pie':饼图 2、dataframe.plot() 2.1 通过 kind 参数设置想要画图的类型 通过dataframe.plot() 中的 kind 参数,可以绘制以下图: ...
DataFrame(dict( number=[2, 5, 1, 6, 3], count=[56, 21, 34, 36, 12], select=[29, 13, 17, 21, 8] )) bar_plot1 = sns.barplot(x='number', y='count', data=df, label="count", color="red") bar_plot2 = sns.barplot(x='number', y='select', data=df, label="select...
df.plot(y='水位')plt.show()3 用两幅上下子图的形式来分别绘制 df.plot(subplots=True,figsize=(8,6))plt.legend(loc='best')4 这里如果对流量和水位按照站点的类别进行分类显示,统计站点A和站点B他的水位流量情况,这里就体现了DataFrame的优势了:df_piv1 = pd.pivot_table(df,index=df.index,columns...
import pandas as pddf = pd.read_csv('data'csv').set_index('time')比如要处理具体的数据,写成代码应该是这样子的。df = pd.DataFrame( { "time": ["1960-01-01", "1961-01-01", "1962-01-01"], "Afghanistan": [1, 2, 3], "Angola": [2, 3, 4], "Albania": [1...
df= pd.DataFrame(np.random.randn(10,4).cumsum(0),columns=['A','B','C','D'])df.plot#plot会自动为不同变量改变颜色,并添加图例<matplotlib.axes._subplots.AxesSubplot at 0xf4f9eb8> Series.plot方法的参数 label:用于图表的标签 style:风格字符串,'g--' ...