34个参数完成,7个未成功,2个删除。

This commit is contained in:
fy3047957834
2021-09-25 23:03:12 +08:00
parent 77406e40a3
commit 8862d6355b
16 changed files with 32 additions and 3068 deletions

View File

@@ -12,25 +12,31 @@ def keep_txt_to_file(code, script_path):
f.write(code)
def scatter_plot(file_path, chart_out_path, out_path, x_scale_font_angle, y_scale_font_angle, group_by_column='color', x_name="x", y_name="y",
def scatter_plot(file_path, chart_out_path, out_path, x_scale_font_angle, y_scale_font_angle, x_column_name, y_column_name, group_by_column='category', x_name="x", y_name="y",
title="chart", dpi=100, width=10, height=6, title_font_size=12, ):
midwest = pd.read_csv(file_path) # 导入文件
plt.figure(figsize=(width, height), dpi=dpi, facecolor='w', edgecolor='k')
plt.figure(figsize=(int(width), int(height)), dpi=int(dpi), facecolor='w', edgecolor='k')
categories = np.unique(midwest[group_by_column])
group_by_column = np.unique(midwest[group_by_column])
colors = [
plt.cm.Set1(i / float(len(group_by_column) - 1)) for i in range(len(group_by_column))
plt.cm.Set1(i / float(len(categories) - 1)) for i in range(len(categories))
]
for i, category in enumerate(group_by_column):
plt.scatter(midwest.keys()[0],
midwest.keys()[1],
data=midwest.loc[midwest[midwest.keys()[2]] == category, :],
for i, category in enumerate(categories):
plt.scatter(x_column_name,
y_column_name,
data=midwest.loc[midwest.category == category, :],
s=20,
c=colors[i],
color=colors[i],
label=str(category))
plt.gca().set(
xlim=(0.0, 0.1),
ylim=(0, 90000),
)
# xy轴的刻度
plt.xticks(rotation=x_scale_font_angle, fontsize=10)
plt.yticks(rotation=y_scale_font_angle, fontsize=10)
@@ -53,7 +59,7 @@ def scatter_plot(file_path, chart_out_path, out_path, x_scale_font_angle, y_scal
def Each_regression_line_in_its_own_column(file_path, chart_out_path, out_path, group_by_column, group_by_range, x_column_name, y_column_name,
title, title_font_size, x_scale_font_angle, y_scale_font_angle, x_name, y_name, color):
title, title_font_size, x_name, y_name, color):
df = pd.read_csv(file_path)
group_by_range = [group_by_range.split("-")[0], group_by_range.split("-")[1]]
df_select = df.loc[df[group_by_column].isin(group_by_range), :]
@@ -73,9 +79,6 @@ def Each_regression_line_in_its_own_column(file_path, chart_out_path, out_path,
plt.title(title, fontsize=int(title_font_size))
plt.savefig(f"{chart_out_path}") # 保存图片
plt.xticks(rotation=x_scale_font_angle, fontsize=10)
plt.yticks(rotation=y_scale_font_angle, fontsize=10)
# xy轴的名称
plt.xlabel(x_name, fontdict={'fontsize': 10})
plt.ylabel(y_name, fontdict={'fontsize': 10})
@@ -86,7 +89,7 @@ def Each_regression_line_in_its_own_column(file_path, chart_out_path, out_path,
def Jittering_with_stripplot(file_path, chart_out_path, out_path, x_column_name, y_column_name,
title, title_font_size, x_scale_font_angle, y_scale_font_angle, x_name, y_name, color):
title, title_font_size, x_name, y_name, color):
df = pd.read_csv(file_path)
fig, ax = plt.subplots(figsize=(5, 3), dpi=180)
print(fig, ax)
@@ -105,9 +108,6 @@ def Jittering_with_stripplot(file_path, chart_out_path, out_path, x_column_name,
plt.legend(fontsize=10)
plt.xticks(rotation=x_scale_font_angle, fontsize=10)
plt.yticks(rotation=y_scale_font_angle, fontsize=10)
# xy轴的名称
plt.xlabel(x_name, fontdict={'fontsize': 10})
plt.ylabel(y_name, fontdict={'fontsize': 10})
@@ -118,7 +118,7 @@ def Jittering_with_stripplot(file_path, chart_out_path, out_path, x_column_name,
def Marginal_Histogram(file_path, chart_out_path, out_path, x_column_name, y_column_name,
title, title_font_size, x_scale_font_angle, y_scale_font_angle, x_name, y_name, chart_bar_x_color='#0078d4', chart_bar_y_color='#098154'):
title, x_name, y_name, chart_bar_x_color='#0078d4', chart_bar_y_color='#098154'):
df = pd.read_csv(file_path)
# Create Fig and gridspec
@@ -156,8 +156,6 @@ def Marginal_Histogram(file_path, chart_out_path, out_path, x_column_name, y_col
orientation='horizontal',
color=chart_bar_y_color)
ax_main.title.set_fontsize(fontsize=int(title_font_size))
ax_main.set(title=title,
xlabel=x_name,
ylabel=y_name)
@@ -173,16 +171,13 @@ def Marginal_Histogram(file_path, chart_out_path, out_path, x_column_name, y_col
plt.legend(fontsize=10)
plt.xticks(rotation=x_scale_font_angle, fontsize=10)
plt.yticks(rotation=y_scale_font_angle, fontsize=10)
plt.savefig(f"{out_path}.png")
plt.savefig(f"{out_path}.svg")
plt.savefig(f"{out_path}.pdf")
def Correllogram(file_path, chart_out_path, out_path,
title, title_font_size, x_scale_font_angle, y_scale_font_angle, x_name, y_name, font_size, font_color, weight):
title, title_font_size, font_size, font_color, weight):
df = pd.read_csv(file_path)
plt.figure(figsize=(9.4, 4.25), dpi=200)
sns.heatmap(
@@ -204,13 +199,6 @@ def Correllogram(file_path, chart_out_path, out_path,
plt.legend(fontsize=10)
plt.xticks(rotation=x_scale_font_angle, fontsize=10)
plt.yticks(rotation=y_scale_font_angle, fontsize=10)
# xy轴的名称
plt.xlabel(x_name, fontdict={'fontsize': 10})
plt.ylabel(y_name, fontdict={'fontsize': 10})
plt.savefig(f"{out_path}.png")
plt.savefig(f"{out_path}.svg")
plt.savefig(f"{out_path}.pdf")
@@ -375,7 +363,7 @@ def Diverging_Bars_vertical(file_path, chart_out_path, out_path, x_column_name,
def Ordered_Bar_Chart(file_path, chart_out_path, out_path, x_column_name, y_column_name,
title, title_font_size, x_scale_font_angle, y_scale_font_angle, x_name, y_name, color):
title, title_font_size, y_scale_font_angle, x_name, y_name, color):
df_raw = pd.read_csv(file_path)
df = df_raw[[x_column_name, y_column_name]].groupby(y_column_name).apply(lambda x: x.mean())
df.sort_values(x_column_name, inplace=True)
@@ -393,7 +381,6 @@ def Ordered_Bar_Chart(file_path, chart_out_path, out_path, x_column_name, y_colu
alpha=0.7,
linewidth=20)
plt.xticks(rotation=x_scale_font_angle, fontsize=10)
plt.yticks(rotation=y_scale_font_angle, fontsize=10)
# Annotate Text
@@ -524,7 +511,7 @@ def Dot_Plot(file_path, chart_out_path, out_path, x_column_name, y_column_name,
plt.yticks(rotation=y_scale_font_angle, fontsize=10)
plt.ylabel(y_name, fontsize=12)
plt.ylabel(x_name, fontsize=12)
plt.xlabel(x_name, fontsize=12)
plt.title(title, fontsize=int(title_font_size))
@@ -1016,7 +1003,7 @@ def Population_Pyramid(file_path, chart_out_path, out_path,
# 测试文件 mpg.csv
def Waffle_Chart(file_path, chart_out_path, out_path, rows_number, group_by_column, data_column, x_scale_font_angle, y_scale_font_angle, y_name, x_name,
def Waffle_Chart(file_path, chart_out_path, out_path, rows_number, group_by_column, x_scale_font_angle, y_scale_font_angle, y_name, x_name,
title_font_size, title):
df_raw = pd.read_csv(file_path)
@@ -1033,10 +1020,10 @@ def Waffle_Chart(file_path, chart_out_path, out_path, rows_number, group_by_colu
plots={
'111': {
'values':
df[data_column],
df['counts'],
'labels': [
"{0} ({1})".format(n[0], n[1])
for n in df[[group_by_column, data_column]].itertuples()
for n in df[[group_by_column, 'counts']].itertuples()
],
'legend': {
'loc': 'upper left',
@@ -1089,7 +1076,7 @@ def Pie_Chart(file_path, chart_out_path, out_path, y_name, title, group_by_colum
# 测试文件 mpg.csv
def Treemap(file_path, chart_out_path, out_path, title, group_by_column, data_column, title_font_size):
def Treemap(file_path, chart_out_path, out_path, title, group_by_column, title_font_size):
import squarify
df_raw = pd.read_csv(file_path)
@@ -1097,7 +1084,7 @@ def Treemap(file_path, chart_out_path, out_path, title, group_by_column, data_co
# Prepare Data
df = df_raw.groupby(group_by_column).size().reset_index(name='counts')
labels = df.apply(lambda x: str(x[0]) + "\n (" + str(x[1]) + ")", axis=1)
sizes = df[data_column].values.tolist()
sizes = df['counts'].values.tolist()
colors = [plt.cm.Set2(i / float(len(labels))) for i in range(len(labels))]
# Draw Plot
@@ -1490,7 +1477,7 @@ def Dendrogram(file_path, chart_out_path, out_path,
def Composition_Bar(file_path, chart_out_path, out_path, title, caption, subtitle, x_name, y_name, title_font_size, x_font_size,
y_font_size, x_scale_font_size, y_scale_font_size, x_scale_font_angle, y_scale_font_angle,
x_font_color, y_font_color, x_scale_font_color, y_scale_font_color, title_font_color, background_color):
x_font_color, y_font_color, x_scale_font_color, y_scale_font_color, title_font_color):
code = f"""
datas <- read.csv("{file_path}")
@@ -1512,7 +1499,6 @@ gg <- g + geom_bar(stat="identity", width = 0.5, fill="tomato2") +
x="{x_name}",
y="{y_name}") +
theme(title=element_text(size={title_font_size}, color="{title_font_color}"),
plot.background_color = element_rect(fill="{background_color}", color="{background_color}"),
axis.text.x=element_text(color="{x_scale_font_color}", size={x_scale_font_size}, angle={x_scale_font_angle}, vjust=0.6), axis.text.y=element_text(color="{y_scale_font_color}", size={y_scale_font_size}, angle={y_scale_font_angle}),
axis.title.x=element_text(size={x_font_size}, color="{x_font_color}"), axis.title.y=element_text(size={y_font_size}, color="{y_font_color}"))
@@ -2389,7 +2375,7 @@ dev.off()
def Distribution_Box_1(file_path, chart_out_path, out_path, title, caption, subtitle, x_name, y_name, title_font_size,
x_font_size, y_font_size, x_scale_font_size, y_scale_font_size, x_scale_font_angle, y_scale_font_angle,
x_font_color, y_font_color, x_scale_font_color, y_scale_font_color, title_font_color, background_color, line_color):
x_font_color, y_font_color, x_scale_font_color, y_scale_font_color, title_font_color, line_color):
file_path = file_path.replace("\\", "\\\\")
code = f"""
@@ -2410,7 +2396,6 @@ gg <- g + geom_boxplot(varwidth=T, fill="plum", color="{line_color}") +
x="{x_name}",
y="{y_name}") +
theme(title=element_text(size={title_font_size}, color="{title_font_color}"),
plot.background_color = element_rect(fill="{background_color}", color="{background_color}"),
axis.text.x=element_text(color="{x_scale_font_color}", size={x_scale_font_size}, angle={x_scale_font_angle}, vjust=0.6), axis.text.y=element_text(color="{y_scale_font_color}", size={y_scale_font_size}, angle={y_scale_font_angle}),
axis.title.x=element_text(size={x_font_size}, color="{x_font_color}"), axis.title.y=element_text(size={y_font_size}, color="{y_font_color}"))
@@ -2873,7 +2858,7 @@ dev.off()
# 实例文件 Group_HierarchicalTree.csv
def Group_HierarchicalTree(file_path, chart_out_path, out_path, title, caption, subtitle, title_font_size,
title_font_color, background_color):
title_font_color):
file_path = file_path.replace("\\", "\\\\")
code = f"""
@@ -2889,8 +2874,7 @@ hc <- hclust(dist(datas), "ave") # hierarchical clustering
gg <- ggdendrogram(hc, rotate = TRUE, size = 2) + labs(title="{title}",
subtitle="{subtitle}",
caption="{caption}") +
theme(title=element_text(size={title_font_size}, color="{title_font_color}"),
plot.background_color = element_rect(fill="{background_color}", color="{background_color}"))
theme(title=element_text(size={title_font_size}, color="{title_font_color}"))
png("{chart_out_path}",width=900,height=408)
plot(gg)

View File

@@ -367,6 +367,7 @@ class="layui-input" style="height: 25px; width:80px;margin-top: 6px">
else:
fl = "hex"
code += """
%s = "#000000"
layui.use('colorpicker', function()
{
var $ = layui.$
@@ -384,7 +385,7 @@ class="layui-input" style="height: 25px; width:80px;margin-top: 6px">
});
})
""" % (i, random_color(), fl, i + "_")
""" % (i + '_', i, random_color(), fl, i + "_")
return code