matplotlib图只有一个y轴tick标记?绘制手动与TKINTER按钮
由于某种原因,当使用 tkinter 按钮调用我的绘图函数时,我的 matplotlib 没有为整个图形添加 y 轴刻度部分。但是,如果我只是手动调用绘图函数,那么 y 轴刻度线就会显示出来。数据在两个图表上都正确绘制。只是其中之一缺少大部分 y 轴刻度线。
使用 tkinter 按钮调用我的绘图函数时的图表
调用时的图表我使用脚本手动绘制函数
注意:这些图表可能看起来像是在绘制两个不同的东西。它们是相同的,只是缩放由于某种原因而混乱。
这是我的 tkinter 按钮调用的函数。它只是设置一些参数并调用图形函数
def plotLightCurve():
myLCG.setCheckChoice(int(checkStarChoice.get()))
myLCG.setChoiceMag(check_star_mag_box.get())
myLCG.ConfigureFile()
myLCG.process_data()
myLCG.LCG_Plot()
这是绘图函数本身
def LCG_Plot(self):
subplot = self.fig.add_subplot(111)
subplot.scatter(self.jd_list, self.c2_app_mag, label="c2 apparent mag.")
subplot.scatter(self.jd_list, self.c3_app_mag, label="c3 apparent mag.")
subplot.scatter(self.jd_list, self.c4_app_mag, label="c4 apparent mag.")
if self.source_c5_list[0] != 0:
subplot.scatter(self.jd_list, self.c5_app_mag, label="c5 apparent mag.")
if self.source_c6_list[0] != 0:
subplot.scatter(self.jd_list, self.c6_app_mag, label="c6 apparent mag.")
subplot.scatter(self.jd_list, self.t1_app_mag, label="t1 apparent mag.")
subplot.legend(title='Object Magnititudes', bbox_to_anchor=(1.05, 1.0), loc='upper left')
# subplot.tight_layout()
plt.scatter(self.jd_list, self.c2_app_mag, label="c2 apparent mag.")
plt.scatter(self.jd_list, self.c3_app_mag, label="c3 apparent mag.")
plt.scatter(self.jd_list, self.c4_app_mag, label="c4 apparent mag.")
plt.show()
这是我用于手动绘制图形的脚本。 注意:文件路径、ChoiceMag 和 CheckChoice 是在 tkinter 版本中设置的。
import LCGLib
myLCG = LCGLib.LCG()
myLCG.setFilePath('Measurements6.csv')
myLCG.setChoiceMag(8.91)
myLCG.setCheckChoice(1)
myLCG.ConfigureFile()
myLCG.process_data()
myLCG.LCG_Plot()
For some reason, my matplotlib isn't adding y-axis tick parts for the whole graph when calling my plotting function with a tkinter button. However, if I just call the plotting function manually, then the y-axis tick marks do show up. The data is being plotted correctly on both graphs. It's just one of them is missing most of the y-axis tick marks.
The graph when calling my plotting function with a tkinter button
The graph when calling my plotting function manually with a script
Note: The graphs may look like they're plotting two different things. They are the same, the scaling is just messed up for some reason.
This is the function my tkinter button calls. It's just setting some parameters and calling the graph function
def plotLightCurve():
myLCG.setCheckChoice(int(checkStarChoice.get()))
myLCG.setChoiceMag(check_star_mag_box.get())
myLCG.ConfigureFile()
myLCG.process_data()
myLCG.LCG_Plot()
This is the plot function itself
def LCG_Plot(self):
subplot = self.fig.add_subplot(111)
subplot.scatter(self.jd_list, self.c2_app_mag, label="c2 apparent mag.")
subplot.scatter(self.jd_list, self.c3_app_mag, label="c3 apparent mag.")
subplot.scatter(self.jd_list, self.c4_app_mag, label="c4 apparent mag.")
if self.source_c5_list[0] != 0:
subplot.scatter(self.jd_list, self.c5_app_mag, label="c5 apparent mag.")
if self.source_c6_list[0] != 0:
subplot.scatter(self.jd_list, self.c6_app_mag, label="c6 apparent mag.")
subplot.scatter(self.jd_list, self.t1_app_mag, label="t1 apparent mag.")
subplot.legend(title='Object Magnititudes', bbox_to_anchor=(1.05, 1.0), loc='upper left')
# subplot.tight_layout()
plt.scatter(self.jd_list, self.c2_app_mag, label="c2 apparent mag.")
plt.scatter(self.jd_list, self.c3_app_mag, label="c3 apparent mag.")
plt.scatter(self.jd_list, self.c4_app_mag, label="c4 apparent mag.")
plt.show()
Here is my script for manually plotting the graph. Note: The filepath, ChoiceMag, and CheckChoice are set elsewere in the tkinter version.
import LCGLib
myLCG = LCGLib.LCG()
myLCG.setFilePath('Measurements6.csv')
myLCG.setChoiceMag(8.91)
myLCG.setCheckChoice(1)
myLCG.ConfigureFile()
myLCG.process_data()
myLCG.LCG_Plot()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论