Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I draw a graph or plot with 4 quadrants using Python matplotlib?

My objective is to draw a graph with 4 quadrants and plot points in the same. And also, how can I divide a quadrant into several sectors? How can I do the same in matplotlib: a graph/plot with 4 quadrants. With x axis (1-9) and y-axis(1-9)?

like image 488
siddarthforever Avatar asked Dec 06 '25 04:12

siddarthforever


2 Answers

From the question, it sounds like you want a single graph with several delineated regions with a specific xy range. This is pretty straightforward to do. You can always just draw lines on the plot to delineate the regions of interest. Here is a quick example based on your stated objectives:

import matplotlib.pyplot as plt

plt.figure()
# Set x-axis range
plt.xlim((1,9))
# Set y-axis range
plt.ylim((1,9))
# Draw lines to split quadrants
plt.plot([5,5],[1,9], linewidth=4, color='red' )
plt.plot([1,9],[5,5], linewidth=4, color='red' )
plt.title('Quadrant plot')
# Draw some sub-regions in upper left quadrant
plt.plot([3,3],[5,9], linewidth=2, color='blue')
plt.plot([1,5],[7,7], linewidth=2, color='blue')
plt.show()

Quadrant Plot

like image 193
T3am5hark Avatar answered Dec 08 '25 18:12

T3am5hark


I would take a look at the AxesGrid toolkit:

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/index.html

Perhaps the middle image at the top of this page is something along the lines of what you are looking for. There are examples on the following page in the API documentation that should be a good starting point:

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html

Without an example of what you want to do exactly it is difficult to give you the best advice.

like image 37
JoshAdel Avatar answered Dec 08 '25 18:12

JoshAdel



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!