import matplotlib.pyplot as plt import pandas as pd plt.rcParams['font.family'] = 'Fangsong' # 指定使用宋体字体 # 读取数据 df = pd.read_excel('200马力拖拉机明细.xlsx') fig= plt.figure(figsize=(1000, 1000), dpi=300) # 绘制箱线图 fig, ax = plt.subplots() bp = df.boxplot(column='sale', by=['FactoryName', 'JiJXH'], ax=ax,rot=90, grid=False) # 修改横轴标签 xtick_labels = [label.get_text() for label in ax.get_xticklabels()] new_xtick_labels = [label.replace(' ', '\n') for label in xtick_labels] ax.set_xticklabels(new_xtick_labels) # 绘制折线图 median_dict = df.groupby(['FactoryName', 'JiJXH'])['sale'].median().to_dict() for i, label in enumerate(xtick_labels): factory_jijxh = tuple(label.split('\n')) median = median_dict.get(factory_jijxh, None) if median is not None: ax.plot(i+1, median, marker='-', color='red') # 显示图形 plt.show() 怎样使图变大
时间: 2023-12-07 19:03:07 浏览: 153
matplotlib.pyplot绘图显示控制方法
5星 · 资源好评率100%
可以调整 `figsize` 参数来改变图的大小,例如将宽度设为 20,高度设为 10:
```
fig= plt.figure(figsize=(20, 10), dpi=300)
```
另外,如果图显示不全,可以调整 `plt.subplots_adjust()` 来控制子图之间的间距,例如:
```
fig, ax = plt.subplots()
plt.subplots_adjust(left=0.1, right=0.9, bottom=0.2, top=0.9, wspace=0.3, hspace=0.3)
bp = df.boxplot(column='sale', by=['FactoryName', 'JiJXH'], ax=ax,rot=90, grid=False)
```
其中,`left` 和 `right` 控制左右边距,`bottom` 和 `top` 控制上下边距,`wspace` 和 `hspace` 控制子图之间的宽度和高度间距。
阅读全文