0

I am trying to create a plot with the y-axis oriented downwards (which I've already done) and locating the x axis at top. It's in this second part where I get the problem, since I am not able to put the xlabel title (called Temperatura) to the top.

Here I add the code (the data is provided by an excel sheet). I would appreciate if someone can tell me how to put it correctly.

Packages:

import pandas as pd    
from matplotlib import pyplot as plt    
import numpy as np

My data (not available here):

DatosPunto = pd.read_excel("C:\\Users\\usuario\\Desktop\\TFM\\Datos Partida\\CTD_Fluorimetro_IRTA\\Datos_RodaminaMañana.xlsx", sheet_name = "1")    
temperatura = DatosPunto['Temp °C']    
profundidad = DatosPunto['Depth m']

Creating the plot:

plot1=plt.figure(1)    
plt.plot(temperatura, profundidad, color='red', linewidth =1.0)    
plt.xlabel('Temperatura, º C ', fontsize=12, fontdict=fontAxis, labelpad=10)    
plt.ylabel('Profundidad, m ', fontsize=12, fontdict=fontAxis,labelpad=10)    
plt.title('Perfil Tª Punto 1', fontsize=18, fontdict=fontTitle, pad=60)

For moving the x axis at top:

plt.tick_params(axis='x', labeltop=True, top=True, bottom=False, labelbottom=False)

And inverting the y axis:

plt.gca().invert_yaxis()
Mr. T
  • 11,141
  • 9
  • 27
  • 51
  • 2
    Does this answer your question? [Moving x-axis to the top of a plot in matplotlib](https://stackoverflow.com/questions/14406214/moving-x-axis-to-the-top-of-a-plot-in-matplotlib) You can use `plt.gca().xaxis.set_label_position('top')`. – Mr. T Mar 12 '22 at 11:27

0 Answers0