0

I try to undestand what happens if I run

import matplotlib.pyplot as plt
plt.plot([1, 2], [5, 2])
plt.plot([1, 2], [4, 4])
plt.show()

How does plt.show() know, that it has to plot two lines in one plot? According to help(plt.plot) twice "A list of .Line2D objects representing the plotted data" is returned; but where are they stored? Since plt is still of type "module", I don't see it as an instance where the data are stored. In R a ggplot instance is created by my_plot <- ggplot(...), and then this object gg could be sent to someone else who could modify this object as he wishes (for example to add axis labels in his own language) and only with show(gg), the image is generated (see for example here).

For matplotlib, I only found how to export the image, but not how to export the graphical instance "below" the image.

Qaswed
  • 3,649
  • 7
  • 27
  • 47
  • If no figure is created by the script, then `plt.plot` creates its own figure and axes. You can get the current figure and axes objects using `plt.gcf()` and `plt.gca()` respectively – DavidG Jun 25 '20 at 15:04
  • By "figure created by the script", do you mean "fig = plt.figure()"? – Qaswed Jun 25 '20 at 15:08

0 Answers0