0

My code displays five graphs together in a small window produced by plt.show(). I find the default window to be too small. How can i resize this so its larger by default, and can i program this window to pop up on a specific place on my screen? I would like to make this pop up window to occupy the entirety of the white background.

Another option could be displaying these graphs in a tkinter canvas. Some context: I have already tried this for 4 days, with a lot of help but no succes. This is why i have resorted to using plt.show().

here is the image:

enter image description here

figure = plt.figure()

canvas = FigureCanvasTkAgg(figure, master=inspect_data) canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)

def items_selected(self):

plt.clf()
selected_indices = vores_listebox.curselection()
selected_json = ",".join([vores_listebox.get(i) for i in selected_indices])
full_file_path = path_us + selected_json
open_json = js.load(open(full_file_path, "r"))
time = [open_json['XML_Data']
        ['Wsk3Vectors']['X_Axis']['Values']['float']]
rpm = [open_json['XML_Data']['Wsk3Vectors']
       ['Y_AxesList']['AxisData'][0]['Values']['float']]
torque = [open_json['XML_Data']['Wsk3Vectors']
          ['Y_AxesList']['AxisData'][1]['Values']['float']]
current = [open_json['XML_Data']['Wsk3Vectors']
           ['Y_AxesList']['AxisData'][2]['Values']['float']]
angle = [open_json['XML_Data']['Wsk3Vectors']
         ['Y_AxesList']['AxisData'][3]['Values']['float']]
depth = [open_json['XML_Data']['Wsk3Vectors']
         ['Y_AxesList']['AxisData'][4]['Values']['float']]

plt.rcParams["figure.figsize"] = (7,10)

plt.subplot(5, 1, 1)
plt.scatter(time, rpm, c="b", linewidths=2,
            marker=",", edgecolor="b", s=1, alpha=0.5)
plt.title(selected_json)
plt.gca().axes.xaxis.set_ticklabels([])
plt.ylabel("RPM")
plt.grid()

plt.subplot(5, 1, 2)
plt.scatter(time, torque, c="g", linewidths=1,
            marker=",", edgecolor="g", s=1, alpha=0.3)
plt.gca().axes.xaxis.set_ticklabels([])
plt.ylabel("Torque [Nm]")
plt.grid()

plt.subplot(5, 1, 3)
plt.scatter(time, current, c="r", linewidths=2,
            marker=",", edgecolor="r", s=1, alpha=0.5)
plt.gca().axes.xaxis.set_ticklabels([])
plt.ylabel("Current [Amps]")
plt.grid()

plt.subplot(5, 1, 4)
plt.scatter(time, angle, c="m", linewidths=2,
            marker=",", edgecolor="m", s=1, alpha=0.5)
plt.gca().axes.xaxis.set_ticklabels([])
plt.ylabel("Angle [RAD]")
plt.grid()

plt.subplot(5, 1, 5)
plt.scatter(time, depth, c="c", linewidths=2,
            marker=",", edgecolor="c", s=1, alpha=0.5)
plt.xlabel("Time [ms]")
plt.ylabel("Depth [mm]")
plt.grid()

plt.show()
  • Quick answer: you can set the size of the figure in inches when calling `plt.figure` https://stackoverflow.com/a/638443/5166365. If you want the inches to be real-world inches, you need to get the dpi of your screen: https://stackoverflow.com/a/60747161/5166365 – Michael Sohnen Nov 15 '22 at 13:23
  • I dont think this works with subplots – Filip Dalsgard Nov 15 '22 at 13:39
  • The following function will prevent labels from overlapping, but I'm not sure how to make each individual subplot larger. `fig=plt.figure();plt.set_tight_layout(True)`. Try combining the two approaches, somethjing like `fig=plt.figure(size=(11,8.5),dpi=80);plt.set_tight_layout(True)` – Michael Sohnen Nov 15 '22 at 13:55

0 Answers0