from matplotlib import pyplot as plt import matplotlib.pyplot as plt
Are the above statements equivalent? Which is more readable/better form?
matplotlib. pyplot is a collection of command style functions that make matplotlib work like MATLAB. Each pyplot function makes some change to a figure: e.g., creates a figure, creates a plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.
Matplotlib is the whole package; matplotlib. pyplot is a module in Matplotlib; and PyLab is a module that gets installed alongside Matplotlib. PyLab is a convenience module that bulk imports matplotlib. pyplot (for plotting) and NumPy (for Mathematics and working with arrays) in a single name space.
Matplotlib is a Python library that helps to plot graphs. It is used in data visualization and graphical plotting. To use matplotlib, we need to install it.
Matplotlib is a cross-platform, data visualization and graphical plotting library for Python and its numerical extension NumPy. As such, it offers a viable open source alternative to MATLAB. Developers can also use matplotlib's APIs (Application Programming Interfaces) to embed plots in GUI applications.
Even though they are equivalent, I think there is a pretty good argument that the second form import matplotlib.pyplot as plt
is objectively more readable:
It is generally customary to use import matplotlib.pyplot as plt
and suggested in the matplotlib documentation (see http://matplotlib.org/users/pyplot_tutorial.html etc...) so this will be more familiar to most readers.
import matplotlib.pyplot as plt
is shorter but no less clear.
import matplotlib.pyplot as plt
gives an unfamiliar reader a hint that pyplot is a module, rather than a function which could be incorrectly assumed from the first form.
They both work the same so it is up to you which you prefer, personally I don't like typing so I would prefer the second.
from matplotlib import pyplot as plt import matplotlib.pyplot as plt1 print(dir(plt) == dir(plt1)) True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With