Matplotlib.pyplot - Deactivate axes in figure. /Axis of figure overlap with axes of subplot

2024/11/21 2:24:55
%load_ext autoreload 
%autoreload 2
%matplotlib inlineimport numpy as np
import datetime as dt
import pickle
import pandas as pd
import datetime
from datetime import timedelta, date
from datetime import date as dt
import math
import os
import matplotlib.pyplot as plt
plt.style.use('ggplot')
from pylab import plot,show
from matplotlib import ticker
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.dates as mdates
import pylab as plx_min_global=datetime.date(2010,1, 1)- timedelta(days=180)
x_max_global=datetime.date(2015,1, 1)+ timedelta(days=180)d = pd.DataFrame(0, index=np.arange(155),columns=['Zeros'])
d = pd.DataFrame(0, index=np.arange(2),columns=['Zeros'])wd=os.getcwd()def format_date(x, pos=None):return pl.num2date(x).strftime('%Y-%m-%d')with PdfPages(wd+'/Plots.pdf') as pdf:#Plot 1: Allfig = plt.figure(facecolor='white',frameon=True,figsize=(30, 30))plt.title('Page One ', y=1.08)axes1 = fig.add_subplot(3,1,1,frameon=False)axes1.set_xlim(x_min_global,x_max_global)axes1.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))#Plot line a at 0-levelaxes1.plot([x_min_global,x_max_global],d.loc[0:1],color='k', linewidth=2.0, markersize=10.0)     # labels and legendaxes1.set_title('Plot 1')plt.xlabel('Time', fontsize=10)plt.ylabel('Y-Values', fontsize=10)axes1.legend(loc='upper left')#-----------------------------------------------------------------------#Plot 2: axes1 = fig.add_subplot(3,1,2,frameon=False)axes1.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))#Plot line a at 0-levelaxes1.plot([x_min_global,x_max_global],d.loc[0:1],color='k', linewidth=2.0, markersize=10.0)# labels and legendaxes1.set_title('Plot 2')plt.xlabel('Time', fontsize=10)plt.ylabel('Y-Values', fontsize=10)axes1.legend(loc='upper left')#-----------------------------------------------------------------------#Plot 3:axes2 = fig.add_subplot(3,1,3,frameon=False)axes2.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))#Plot line a at 0-levelaxes2.plot([x_min_global,x_max_global],d.loc[0:1],color='k', linewidth=2.0, markersize=10.0)# labels and legendaxes2.set_title('Plot 3')plt.xlabel('Time', fontsize=10)plt.ylabel('Y-Values', fontsize=10)axes2.legend(loc='upper left')pdf.savefig(frameon=False,transparent=False,papertype='a4')  # saves the current figure into a pdf pageplt.show()plt.close()

My problem is that in the plot generated by code above the axis of the figure and the sublpots seem to overlap (see red rectangles in picture). I tried to turn off the axes in the figure. However, I was not able to figure it out.

Any help is appreciated. Thank you.

Output of Code / Problem:

Answer

If you want to remove the axes completely, you should try:

plt.axis('off')

If that doesn't work (or doesn't do what you want it to), try:

cur_axes = plt.gca()
cur_axes.axes.get_xaxis().set_visible(False)
cur_axes.axes.get_yaxis().set_visible(False)
https://en.xdnf.cn/q/118340.html

Related Q&A

How to generate the captcha to train with Python

I would like to use deep learning program for recognizing the captcha using keras with python.But the big challenge is to generate massive captcha to train. I want to solve a captcha like thisHow can …

Convert PNG to a binary (base 2) string in Python

I Basically want to read a png file and convert it into binary(base 2) and store the converted base 2 value in a string. Ive tried so many things, but all of them are showing some error

Turbodbc installation on Windows 10

I tried installing turbodbc and it gives me the following error and not sure whats wrong here.My python version is 3.7My command line output from Windows 10 Pro. C:\Users\marunachalam\Downloads>pip …

how to convert a text into tuples in a list in python

I am a beginner in python and desperately need someones help.I am trying to convert a text into tuples in a list. The original text was already tokenized and each pos was tagged as below:The/DT Fulton/…

Trying to call a function within class but its not working [duplicate]

This question already has answers here:TypeError: attack() missing 1 required positional argument: self(2 answers)Closed 3 years ago.I am trying to call a function but its not working. here is the code…

Tkinter Label not showing Int variable

Im trying to make a simple RPG where as you collect gold it will be showed in a label, but it doesnt!! Here is the code:def start():Inv=Tk()gold = IntVar(value=78)EtkI2=Label(Inv, textvariable=gold).pa…

How to refer a certain place in a line in Python

I have this little piece of code:g = open("spheretop1.stl", "r") m = open("morelinestop1.gcode", "w") searchlines = g.readlines() file = "" for i, line…

List comprehension output is None [duplicate]

This question already has answers here:Python list comprehension: list sub-items without duplicates(6 answers)Closed 8 years ago.Im new to python and I wanted to try to use list comprehension but outco…

error while inserting into mysql from python for loop [duplicate]

This question already has answers here:Closed 12 years ago.Possible Duplicate:convert list to string to insert into my sql in one row in python scrapy Is this script correct. I want to insert the scra…

Half of Matrix Size Missing

I wanted to ask why is it that some of my matrices in Python are missing a size value? The matrices/arrays that re defined show the numbers in them, but the size is missing and it is throwing me other…