logo
down
shadow

log2 axis doesn't work for histograms in matplotlib/seaborn


log2 axis doesn't work for histograms in matplotlib/seaborn

By : Jrebolledo
Date : November 21 2020, 11:01 PM
help you fix your problem when plotting a histogram using matplotlib/seaborn i would like to change the x-axis to be in log2 scale. the data plotted are here , It is neither! See what happens if you increase the number of bins:
code :
plt.hist(df["y"], bins = 300)
ax1.set_xscale("log", basex=2)
ax2 = plt.subplot(2, 1, 2)
plt.hist(np.log2(df["y"]), bins=300)
plt.figure()
sns.set_style("ticks")
ax1 = plt.subplot(2, 1, 1)
logbins = np.logspace(np.log2(df["y"].min()),
                      np.log2(df["y"].max()),
                      300, base=2)
plt.hist(df["y"], bins = logbins)
ax1.set_xscale("log", basex=2)
ax2 = plt.subplot(2, 1, 2)
plt.hist(np.log2(df["y"]), bins=300)


Share : facebook icon twitter icon
Displaying 3 histograms on 1 axis in a legible way - matplotlib

Displaying 3 histograms on 1 axis in a legible way - matplotlib


By : Om Id
Date : March 29 2020, 07:55 AM
around this issue There are two ways to plot three histograms simultaniously, but both are not what you've asked for. To do what you ask, you must calculate the histogram, e.g. by using numpy.histogram, then plot using the plot method. Use scatter only if you want to associate other information with your points by setting a size for each point.
The first alternative approach to using hist involves passing all three data sets at once to the hist method. The hist method then adjusts the widths and placements of each bar so that all three sets are clearly presented.
code :
import numpy as np
import matplotlib.pyplot as plt

np.random.seed(101)
a = np.random.normal(size=1000)
b = np.random.normal(size=1000)
c = np.random.normal(size=1000)

common_params = dict(bins=20, 
                     range=(-5, 5), 
                     normed=True)

plt.subplots_adjust(hspace=.4)
plt.subplot(311)
plt.title('Default')
plt.hist(a, **common_params)
plt.hist(b, **common_params)
plt.hist(c, **common_params)
plt.subplot(312)
plt.title('Skinny shift - 3 at a time')
plt.hist((a, b, c), **common_params)
plt.subplot(313)
common_params['histtype'] = 'step'
plt.title('With steps')
plt.hist(a, **common_params)
plt.hist(b, **common_params)
plt.hist(c, **common_params)

plt.savefig('3hist.png')
plt.show()
how to set bounds for the x-axis in one figure containing multiple matplotlib histograms and create just one column of g

how to set bounds for the x-axis in one figure containing multiple matplotlib histograms and create just one column of g


By : Mughees
Date : March 29 2020, 07:55 AM
To fix the issue you can do There are two subplots, and you can access each of them and modify them seperately:
code :
ax_list=df.hist()
ax_list[0][0].set_xlim((0,1))
ax_list[0][1].set_xlim((0.01, 0.07))
ax_list=df.hist(layout=(2,1),bins=np.histogram(df.values.ravel())[1])
ax_list[0][0].set_xlim((0.01, 0.07))
ax_list[1][0].set_xlim((0.01, 0.07))
ax_list=df.hist(layout=(2,1),bins=np.linspace(-1,1,10))
ax_list[0][0].set_xlim((-1,1))
ax_list[1][0].set_xlim((-1,1))
No outlines on bins of Matplotlib histograms or Seaborn distplots

No outlines on bins of Matplotlib histograms or Seaborn distplots


By : jlau
Date : March 29 2020, 07:55 AM
help you fix your problem As part of the update to matplotlib 2.0 the edges on bar plots are turned off by default. However, you may use the rcParam
code :
plt.rcParams["patch.force_edgecolor"] = True
ax = sns.distplot(x, hist_kws=dict(edgecolor="k", linewidth=2))
plt.bar(x,y, edgecolor="k")
plt.hist(x, edgecolor="k")
df.plot(kind='hist',edgecolor="k")
import  numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

x = np.random.randn(100)
ax = sns.distplot(x, hist_kws=dict(edgecolor="k", linewidth=2))
plt.show()
matplotlib: unreadable scatter plots and histograms on shared axis with logscale

matplotlib: unreadable scatter plots and histograms on shared axis with logscale


By : gauri
Date : March 29 2020, 07:55 AM
I hope this helps . I do not exactly know the reason why this fails, I could imagine that the problem is related to the data ranging to below 0 for which a log scale is not defined.
In any case you would need to set the limits of the plot manually,
code :
ax.set_yscale('log')
ax.set_ylim(1,None)
ax.set_yscale('symlog')
Share x axis between matplotlib and seaborn

Share x axis between matplotlib and seaborn


By : Rizky Prilian Dwicah
Date : March 29 2020, 07:55 AM
hope this fix your issue The x-axis in the barplot is categorical, so it doesn't have the values of your df.a as a real scale, but only as tick labels. You could change e.g. df.a[19] = 2 and nothing will change except the label of the last bar tick.
So categorical axis means the coordinates are 0 for the first bar, 1 for the second and so on ... 19 for the last.
code :
plt.vlines(x = .45*19/.95, ymin = 0, ymax = 0.6, color = 'red', linewidth=5)
f = lambda x: (x-df.a.values[0]) * (df.a.size-1) / (df.a.values[-1] - df.a.values[0])
plt.vlines(x = f(.45), ymin = 0, ymax = 0.6, color = 'red', linewidth=5)
Related Posts Related Posts :
  • Django Form Based on Variable Attributes
  • Relocate all the evens
  • How to scrap span ids' texts in beautifulsoup in the following html?
  • How to generate random number in a given range as a Tensorflow variable
  • Gradient Descent Variation doesn't work
  • Python 2.7 - search for a particular URL on a webpage with ajax
  • How to configure Luigi task retry correctly?
  • web.py : an urlencoded slash into args
  • Use of pyzmq's logging handler in python
  • How to count the number of a particular entry. python
  • devide int into lower whole ints
  • Access atribute of every object in pandas dataframe column
  • Combine Dataframe rows on conditions
  • Select closest date (or value) in pandas / python
  • Pycharm and remote interpreter (Docker) shows errors but runs fine
  • Get started to launch google-cloud-ml with my own dataset
  • Multiprocessing: use only the physical cores?
  • Django Login Custom Auth works locally but not on production server
  • Python: Invalid HTTP basic authentication header with long base64 string
  • How can I request several pages without wating for the output?
  • Flask Response vs Flask make_response
  • python linear regression predict by date
  • How to get pandas dataframe where columns are the subsequent n-elements from another column dataframe?
  • MYSQL: "Access denied for user 'X'@'localhost' (using password: YES)" PYTHON
  • install scipy package via pycharm in windows 10 64 bit - python 3.5
  • Update time in linux and solaris machines from robot framework
  • Complex pandas isin function
  • Averaging over every n elements of an array without numpy
  • An elegant way of inserting multiple arguments
  • IntegrityError:NOT NULL constraint failed: chatapp_chat.message
  • Indexing of 3d numpy arrays with 2d arrays
  • Creating a mean of columns with csv writer
  • Reading in environment variables from an environment file
  • Collapse duplicate rows with pandas
  • How can I use skyfied to convert SGP4 TEME coordinate to ECEF?
  • How to modify object in Python's Rtree index
  • Create Hexbin plot with pandas dataframe using index and columns names as x and y
  • SQLAlchemy query returns no data if a database field is empty
  • Python pandas column asignment between dataframe and series does not work
  • ValueError: Unknown label type: array while using Decision Tree Classifier and using a custom dataset
  • Trouble accessing exif information with PIL.Image._getexif()
  • Use all coordinates in a grid except with certain value
  • Why for loop is splitting strings of user input?
  • How can I add two variable and assign to result variable in Python?
  • Error when parsing timestamp with pandas read_csv
  • Slicing arrays based on boolean array in python
  • Feeding scipy.sparse() sparse matrices into CVXOPT
  • How to separate a irregularly cased string to get the words? - Python
  • Pandas: replace some values in column if that contain a substring
  • Fabric does not close the ssh connection
  • Python Creating Classes Code
  • When will train() method in easy_seq2seq stop?
  • How to split each element of the RDD in spark with python?
  • Read in csv file in python, round the values and write back to file
  • How to properly close a QWidget-window in an API with PythonQt
  • How to know which segment a value reside in
  • pandas: convert multiple categories to dummies
  • 'Options' object has no attribute 'get_all_field_names'
  • Customize django filter model field
  • NLTK tag Dutch sentence
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com