matplotlib hexbin log scale

  • Last Update :
  • Techknowledgy :

Here is a subset of my data and some accompanying images. The total arrays contain 6,521 values.

x_data = [1.81, 1.516, 6.985, 5.442, 9.419, 1.014, 0.751, 3.77, 1.337, 7.696, 0.491, 0.63, 0.484, 7.165, 0.343, 2.057, 0.218, 0.485, 3.311, 5.976, 3.904, 0.805, 3.94, 0.579, 2.325, 1.57, 0.759, 1.261, 3.975, 0.944]

y_data = [2.069, 0.076, 2.272, 0.501, 0.536, 4.144, 1.452, 7.798, 1.176, 0.832, 0.133, 0.674, 5.275, 1.87, 0.44, 0.229, 0.396, 1.448, 0.514, 0.646, 3.776, 2.2, 1.588, 1.193, 1.005, 1.181, 0.325, 2.47, 1.766, 0.754]

There is no problem plotting my data to a log scale with a normal scatter plot.

plt.scatter(x_data, y_data, alpha = 0.05)
plt.xscale('log')
plt.yscale('log')
ax.set_ylim(0.001, 100)
ax.set_xlim(0.001, 100)

However, when I try to implement a hexbin I get something like this. I've trying playing with the gridesize=, bins=, and mincnt= and couldn't really get anywhere.

plt.xscale('log')
plt.yscale('log')
ax.set_ylim(0.001, 100)
ax.set_xlim(0.001, 100)
plt.hexbin(x_data, y_data, gridsize = (150, 150), mincnt = 2)

Suggestion : 2

I assume you want the histogram to be on anycodings_python-3.x a log scale, rather than the axes.,Matplotlib gives you 3 arguments: bins, anycodings_python-3.x xscale, and yscale that all can be set anycodings_python-3.x to log. When you want both axes to be on anycodings_python-3.x a log scale, setting bins='log' worked anycodings_python-3.x great for me.,I am having difficulty getting matplotlib anycodings_python-3.x hexbin to work with a log scale.,There is no problem plotting my data to a anycodings_python-3.x log scale with a normal scatter plot.

Here is a subset of my data and some anycodings_python-3.x accompanying images. The total arrays anycodings_python-3.x contain 6,521 values.

x_data = [1.81, 1.516, 6.985, 5.442, 9.419, 1.014, 0.751, 3.77, 1.337, 7.696, 0.491, 0.63, 0.484, 7.165, 0.343, 2.057, 0.218, 0.485, 3.311, 5.976, 3.904, 0.805, 3.94, 0.579, 2.325, 1.57, 0.759, 1.261, 3.975, 0.944]

y_data = [2.069, 0.076, 2.272, 0.501, 0.536, 4.144, 1.452, 7.798, 1.176, 0.832, 0.133, 0.674, 5.275, 1.87, 0.44, 0.229, 0.396, 1.448, 0.514, 0.646, 3.776, 2.2, 1.588, 1.193, 1.005, 1.181, 0.325, 2.47, 1.766, 0.754]

There is no problem plotting my data to a anycodings_python-3.x log scale with a normal scatter plot.

plt.scatter(x_data, y_data, alpha = 0.05)
plt.xscale('log')
plt.yscale('log')
ax.set_ylim(0.001, 100)
ax.set_xlim(0.001, 100)

However, when I try to implement a hexbin I anycodings_python-3.x get something like this. I've trying playing anycodings_python-3.x with the gridesize=, bins=, and mincnt= and anycodings_python-3.x couldn't really get anywhere.

plt.xscale('log')
plt.yscale('log')
ax.set_ylim(0.001, 100)
ax.set_xlim(0.001, 100)
plt.hexbin(x_data, y_data, gridsize = (150, 150), mincnt = 2)

Suggestion : 3

The hexbin() function in the pyplot library is used to represent data in the 2D hexagonal plot by binning the points from the x-axis and y-axis.,xscale: This is the log10 or linear scale along the horizontal axis. Its default value is 'linear'.,yscale: This is the log10 or linear scale along the vertical axis. Its default value is 'linear'.,The Matplotlib library in Python helps us fabricate animated and interactive data visualization. It is also used to perform many statistical functions, including the calculation of average, median, and variance, and plot data inferences.

matplotlib.pyplot.hexbin(x, y, C = None, gridsize = 100, bins = None,
   xscale = 'linear', yscale = 'linear', extent = None, cmap = None, norm = None,
   vmin = None, vmax = None, alpha = None, linewidths = None, edgecolors = 'face',
   mincnt = None, marginals = False, *, data = None, ** kwargs)
import matplotlib.pyplot as plot
import datetime
import numpy as np
# seed a random number
np.random.seed(int(datetime.datetime.utcnow().timestamp()))
# total data points
n = 200000
x = np.random.standard_normal(n)
y = 15 * np.random.standard_normal(n)
# plot hexbin plot with grid size 70
# in blue color shades
plot.hexbin(x, y, gridsize = 70, cmap = 'Blues')
plot.title('The hexbin() Example')
# It is used to display results in the plot format
plot.savefig('output/graph.png')