Python Forum
Making a plot with secondary y-axis bigger
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a plot with secondary y-axis bigger
#1
Hello I'm new here, I hope someone can help me :)
I'm trying to understand how to make a plot, which has a secondary axis, bigger. I tried with plt.figure() but didn't work. Also would like to know how to adjust the x-axis, for example using something like this plt.xticks(rotation=45).

I'm working with this example I found online:

# Adding a Y-Axis Label to
# the Secondary Y-Axis in Matplotlib
# importing the libraries
import pandas as pd
import matplotlib.pyplot as plt
 
#creating dataframe for plot
dataset = pd.DataFrame({'Name':['Rohit', 'Seema',
                                'Meena', 'Geeta',
                                'Rajat'],
                         
                   'Height': [155,129,138,164,145],
                   'Weight': [60,40,45,55,60]})
 
# creating axes object and defining plot
ax = dataset.plot(kind = 'line', x = 'Name',
                  y = 'Height', color = 'Blue',
                  linewidth = 3)
 
ax2 = dataset.plot(kind = 'line', x = 'Name',
                   y = 'Weight', secondary_y = True,
                   color = 'Red',  linewidth = 3,
                   ax = ax)
 
#title of the plot
plt.title("Student Data")
 
#labeling x and y-axis
ax.set_xlabel('Name', color = 'g')
ax.set_ylabel('Height', color = "b")
ax2.set_ylabel('Weight', color = 'r')
 
#defining display layout
plt.tight_layout()
 
#show plot
plt.show()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple user defined plots with secondary axes using for loop maltp 1 1,466 Apr-30-2022, 10:19 AM
Last Post: maltp
  How to invert scatter plot axis Mark17 3 2,538 Sep-22-2021, 04:45 PM
Last Post: jefsummers
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 4,402 Sep-14-2021, 08:29 AM
Last Post: hobbyist
  Counting number of words and organize for the bigger frequencies to the small ones. valeriorsneto 1 1,684 Feb-05-2021, 03:49 PM
Last Post: perfringo
  How to plot intraday data of several days in one plot mistermister 3 2,933 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  Difference Between Figure Axis and Sub Plot Axis in MatplotLib JoeDainton123 2 2,489 Aug-21-2020, 10:17 PM
Last Post: JoeDainton123
  Convert Int Value bigger 256 to Unicode lastyle 4 2,755 Mar-19-2020, 11:48 AM
Last Post: lastyle
  How to plot vertically stacked plot with same x-axis and SriMekala 0 1,944 Jun-12-2019, 03:31 PM
Last Post: SriMekala
  Independent Secondary index for dictionary Larz60+ 10 4,873 Dec-20-2018, 07:59 PM
Last Post: buran
  tkinter - Make circle for radio button bigger Raptor88 5 14,224 Mar-07-2017, 12:13 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020