【发布时间】:2020-05-13 12:30:04
【问题描述】:
我想绘制矩形以及数据的 x 轴分类值。
一些类似但不是我要找的帖子。
matplotlib: how to draw a rectangle on image
Plotting shapes in Matplotlib through a loop
Weird behavior of matplotlib plt.Rectangle
我想将矩形移动到每个后续的 x 值。并单独保存所有图像。
上图的代码(带有矩形的初步代码):
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
data = pd.DataFrame(raw_data, columns = ['first_name', 'pre_score'])
order = np.sort(data['first_name'].unique())
save_images = r'D:\test'
for x_names in order:
print(x_names)
sns.set_style("ticks")
ax = sns.stripplot(x='first_name', y='pre_score', hue='first_name',order=order, jitter=True, dodge=False, size=6, zorder=0, alpha=0.5, linewidth =1, data=data)
ax = sns.boxplot(x='first_name', y='pre_score', hue='first_name',order=order, dodge=False, showfliers=True, linewidth=0.8, showmeans=True, width=0.28, data=data)
ax = sns.pointplot(x='first_name', y='pre_score', order=order, data=data, ci=None, color='black')
fig_size = [18.0, 10.0]
plt.rcParams["figure.figsize"] = fig_size
ax.yaxis.set_tick_params(labelsize=14)
ax.xaxis.set_tick_params(labelsize=14)
plt.Rectangle((0, 0), 0.28, max(data['pre_score']), color="red");
# ax.add_patch(plt.Rectangle(x_names, fill=False, linewidth=2.0))
plt.savefig(save_images +x_names+'.png', dpi=150,bbox_inches="tight")
【问题讨论】:
-
你目前得到了什么?没有
raw_data信息,我无法生成当前绘图。 -
@SathishSanjeevi 原始数据在底部!
-
与此相比,额外的难度是多少? stackoverflow.com/questions/37435369/…
标签: python matplotlib