1

I have created a GUI with customtkinter to plot charts. One of the options I have is a drop down menu of different themes. When I run the script in PyCharm, the selected theme in the drop down option box is applied. When I run the script through the terminal or an executable I have made, the themes do not get applied.

I have uninstalled and reinstalled matplotlib in my main system interpreter. I have imported matplotlib as plt and am using plt.style.use() in my script.

When run from the terminal (not an ide), I tried to set the theme in a drop down option box, and expected said theme to be applied but it did not work.

def generate_plot():
x = df[drp_sel_plt_x.get()]
x = list(set(x))

x_start = int(ent_x_lbl_start.get())
y_start = float(ent_y_lbl_start.get())

x_end = int(ent_x_lbl_end.get())
y_end = float(ent_y_lbl_end.get())

y_plt_rot = int(ent_plt_rot.get())
x_inc = int(ent_x_inc_end.get())
y_inc = float(ent_y_inc.get())

for f in range(len(x)):
    x[f] = float(x[f])
    x[f] = round(x[f])
y = []

for i in range(len(x)):
    value = x[i]
    y_temp = df[df[drp_sel_plt_x.get()] == value][drp_sel_plt_y.get()]
    y_temp = y_temp.mean()
    y.append(y_temp)
    
y_ticks_min = min(y)
y_ticks_max = max(y)
y_ticks = np.arange(y_ticks_min, y_ticks_max, 10)

x_lbl = ent_x_lbl.get()
y_lbl = ent_y_lbl.get()
title = ent_tit_lbl.get()

style = drp_plt_sty.get()
plt.style.use(style)
plt.plot(x, y, linestyle=drp_line_plt_x.get(), marker=drp_mrkr_plt_x.get())
plt.xticks(x, rotation=y_plt_rot, )
plt.yticks(y_ticks)
plt.gca().set_xticklabels(x)  # Set the tick labels
ax = plt.gca()
# Set x-axis major ticks with custom increments
ax.xaxis.set_major_locator(ticker.MultipleLocator(x_inc))
# Set y-axis major ticks with custom increments
ax.yaxis.set_major_locator(ticker.MultipleLocator(y_inc))
plt.xlabel(x_lbl)
plt.ylabel(y_lbl)
plt.title(title)
plt.xlim(x_start, x_end)
plt.ylim(y_start, y_end)
plt.show()
2
  • 1
    Added the functions code... Commented Jun 17, 2024 at 2:25
  • Thanks for the PHD level English lesson, that's what I needed. Commented Jun 17, 2024 at 14:51

1 Answer 1

0

One cannot change the style of an existing figure with plt.style.use, see e.g. How can I change the style of a Matplotlib plot, after it is created?.

If you would define a new figure (e.g. plt.figure() at the start of generate_plot()) this approach would work. But it might break your intended interaction.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.