Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gca and latest version of Matplotlib

Tags:

matplotlib

I've just installed the latest version of Matplotlib (3.4.1). When I use some code with the following line

ax = fig.gca(projection='3d')

I get the following warning:

Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. 
Starting two minor releases later, gca() will take no keyword arguments.  
The gca() function should only be used to get the current axes,
or if no axes exist, create new axes with default keyword arguments.
To create a new axes with non-default arguments,
use plt.axes() or plt.subplot().

How do I get round this so my code does not give this warning?

like image 390
Dan317 Avatar asked Apr 14 '21 16:04

Dan317


People also ask

What is GCA () Matplotlib?

The gca() function in pyplot module of matplotlib library is used to get the current Axes instance on the current figure matching the given keyword args, or create one.

What is GCA and GCF in Matplotlib?

Difference Between Matplotlib gca and gcf:GCA. GCF. stands for get current axis. stands for get current figure. gives the reference of the current axes.

What is Matplotlib Pyplot as PLT?

Pyplot is an API (Application Programming Interface) for Python's matplotlib that effectively makes matplotlib a viable open source alternative to MATLAB. Matplotlib is a library for data visualization, typically in the form of plots, graphs and charts.

What is Matplotlib fig?

figure. The figure module provides the top-level Artist , the Figure , which contains all the plot elements. The following classes are defined SubplotParams control the default spacing of the subplots Figure. Top level container for all plot elements.

What is Matplotlib GCA in Python?

Matplotlib is an in-built library available in Python. It is essentially a numerical and mathematical extension of Python’s NumPy library. Pyplot is a MATLAB like interface provided by the matplotlib module. The GCA () function is used to get the current Axes instance on the current figure matching the given keyword args or create one.

How do I get the current axes in Matplotlib?

matplotlib.pyplot.gca () Function The gca () function in pyplot module of matplotlib library is used to get the current Axes instance on the current figure matching the given keyword args, or create one.

How to get the axes of a plot using GCA?

The gca () function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes () or plt.subplot (). How do I get round this so my code does not give this warning? Show activity on this post. Show activity on this post.

Where can I use Matplotlib?

Check out our home page for more information. Matplotlib produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits.


Video Answer


2 Answers

You can try:

fig = plt.figure()
ax = fig.add_subplot(projection='3d')
like image 154
Akroma Avatar answered Oct 20 '22 12:10

Akroma


fig = plt.figure()
plt.subplot(projection='3d')

plt.plot([0, v1[0]], [0, v1[1]], [0, v1[2]], 'b')
plt.plot([0, v2[0]], [0, v2[1]], [0, v2[2]], 'r')

or

fig = plt.figure()
ax = fig.add_subplot(projection='3d')

ax.plot([0, v1[0]], [0, v1[1]], [0, v1[2]], 'b')
ax.plot([0, v2[0]], [0, v2[1]], [0, v2[2]], 'r')

instead of

fig = plt.figure()
ax = fig.gca(projection='3d')

ax.plot([0, v1[0]], [0, v1[1]], [0, v1[2]], 'b')
ax.plot([0, v2[0]], [0, v2[1]], [0, v2[2]], 'r')

I hope this was helpful,

like image 1
Mehdi Chajadine Avatar answered Oct 20 '22 11:10

Mehdi Chajadine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!