logo
down
shadow

Matplotlib multiple Y-axes, xlabels disappear?


Matplotlib multiple Y-axes, xlabels disappear?

By : deimonwing
Date : October 19 2020, 08:10 AM
it fixes the issue I am working with Python 3.x to generate boxplots using matplotlib. , Try this to set your xaxis ticks:
code :
l1 = [32107.0,20490.0, 32107.0, 22134.0,31564.0, 32107.0, 22134.0, 20732.0, 20490.0, 28406.0]

l2 = [54.4, 40.2, 54.4, 41.1, 49.4, 54.4, 41.1, 37.0, 40.2, 34.2]

l3 = [4595.0, 2164.0, 4595.0, 3500.0, 3733.0, 4595.0, 3500.0, 3214.0, 2164.0, 3388.0]

l4 = [4868.0, 2289.0, 4868.0, 3652.0, 4128.0, 4868.0, 3652.0, 3418.0, 2289.0, 3980.0]

l5 = [3777.0, 1623.0, 3777.0, 2456.0, 3010.0, 3777.0, 2456.0, 2318.0, 1623.0, 2677.0]

df2 = pd.DataFrame(
    {'l1' : l1,
     'l2' : l2,
     'l3': l3,
     'l4' : l4,
     'l5' : l5})
fig, ax = plt.subplots(figsize=(5, 3))

ax.boxplot(df2[['l1']].transpose())
ax2 = ax.twinx()
ax2.boxplot(df2['l2'], positions = [2])
ax3 = ax.twinx()
# ax3.boxplot(df2[['l3','l4','l5']], positions = [3,4,5])
df2[['l3','l4','l5']].plot.box(positions=[3,4,5], ax=ax3)
ax.set_xlim(0, 7)
_ = ax3.xaxis.set_ticks([1,2,3,4,5])
_ = ax3.xaxis.set_ticklabels(['l1','l2','l3','l4','l5'])


Share : facebook icon twitter icon
loglog plot with matplotlib in pyqt - axes disappear

loglog plot with matplotlib in pyqt - axes disappear


By : jose galera
Date : March 29 2020, 07:55 AM
around this issue This is probably because your x-range includes 0. True log scales can't reach 0. If you want to include 0, you'll need to use 'semilog' instead.
Judging from the error message you're getting, I'd bet you're using a fairly old release of matplotlib? For what it's worth, in newer versions, including 0 will cause the scale to be automatically changed to semilog instead of log.
code :
self.axes.set(xscale='semilog', yscale='semilog')
Matplotlib setting xlabels

Matplotlib setting xlabels


By : Leandro Hagen
Date : March 29 2020, 07:55 AM
will be helpful for those in need I'm having trouble setting the x/ylabel for my matplotlib plot, which is using data from a sql query. , Pass the argument ax to df.plot,
code :
fig, ax = plt.subplots()

df.plot(kind='bar', ax=ax, title="BirthMonthCounts", figsize=(15,10), legend=False, fontsize=12, x='BirthMonth', y='Cnt', xticks='BirthMonth')
Is there any way to assign multiple xlabels at once in matplotlib?

Is there any way to assign multiple xlabels at once in matplotlib?


By : Smile Heart
Date : March 29 2020, 07:55 AM
I hope this helps . I want to assign multiple xlabels at once in matplotlib. Now I assign multiple xlabels as follows. , You may use a list comprehension.
code :
[ax.set_xlabel("x label") for ax in [ax1,ax2]]
fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, subplot_kw=dict(xlabel="xlabel") )
Defining xlabels with set() and changing bottom arg inside subplots_adjust() matplotlib will modify xlabels order

Defining xlabels with set() and changing bottom arg inside subplots_adjust() matplotlib will modify xlabels order


By : Scarlie
Date : March 29 2020, 07:55 AM
may help you . I have this two Dataset to plot: , The problem
The xlabels change position due to set.
code :
customer_list=lwm['Client name'] 
customer_list=set(lwm['Client name'])
test1=lwm.sort_values(by=['CTR'], ascending=False)
test2=pwm.sort_values(by=['CTR'], ascending=False)
customer_list2=test1['Client name']
matplotlib multiple overlapping xlabels in 2 levels

matplotlib multiple overlapping xlabels in 2 levels


By : user3722270
Date : March 29 2020, 07:55 AM
may help you . I'm trying to find a solution to a situation where I have multiple xlabels in the plot, which I cannot give up any. , Two approaches
code :
import numpy as np
import matplotlib.pyplot as plt

# call this function in xticks parameters
def transform_xlabels(xlabels):
    return ('\n\n%s' % label if i % 2 else label for i, label in enumerate(xlabels))


N = 5
menMeans = (20, 35, 30, 35, 27)
womenMeans = (25, 32, 34, 20, 25)
menStd = (2, 3, 4, 1, 2)
womenStd = (3, 5, 2, 3, 3)
ind = np.arange(N)    # the x locations for the groups
width = 0.35       # the width of the bars: can also be len(x) sequence

p1 = plt.bar(ind, menMeans, width, yerr=menStd)
p2 = plt.bar(ind, womenMeans, width,
             bottom=menMeans, yerr=womenStd)

plt.ylabel('Scores')
plt.title('Scores by group')
test = 'G1 abc \ndaido misco iso'
xlabels = ('G1 %s' % test, 'G2 %s' % test, 'G3 %s'  % test, 'G4 %s'  % test, 'G5 %s'  % test)

# function is called
plt.xticks(ind, transform_xlabels(xlabels))
plt.yticks(np.arange(0, 81, 10))
plt.legend((p1[0], p2[0]), ('Men', 'Women'))

plt.show()
Related Posts Related Posts :
  • How to use an API that requires user's entry (Sentiment Analysis)
  • Django first app
  • Why is this regex code not working
  • Beautifulsoup - findAll not finding string when link is also in container
  • Python: any() to check if attribute in List of Objects matches a list
  • How do I "enrich" every record in a Pandas dataframe with an hour column?
  • Failing to open an Excel file with Python
  • Python function to modify string
  • Pandas DataFrame seems not to have "factorize" method
  • Row column operations in CSV
  • How to decrypt RSA encrypted file (via PHP and OpenSSL) with pyopenssl?
  • How can we use pandas to generate min, max, mean, median, ...as new columns for the dataframe?
  • Cython: creating an array throws "not allowed in a constant expression"
  • Different thing is shown in html
  • sublimetext3 event for program exit
  • Join contigous tokens if the token includes "@" char
  • transparent background in gif using Python Imageio
  • Enable autologin into flask app using active directory
  • Make a NxN array of 1x3 arrays of random numbers (python)
  • django how to use Max and Count on the same field in back-to-back annotations
  • Using the OR operator seems to only take the first of two conditions when used with np.where filter
  • Elegant Dataframe Operations in Pandas
  • Change metadata of pdf file with pypdf2
  • How can I animate a set of points with matplotlib?
  • error: (-215) count >= 0 && (depth == CV_32F || depth == CV_32S) in function arcLength
  • OpenStack KeyStone SSL Exception When Creating an Instance of KeyStone
  • pyspark: The system cannot find the path specified
  • How can I set path to load data from CSV file into PostgreSQL database in Docker container?
  • Summation in python dictionary
  • DRF 3.7.0 removed handling None in fields and broke my foreign key source fields. Is there a way around it?
  • Error with Padlen in signal.filtfilt in Python
  • Abstract matrix multiplication with variables
  • Reading binary data on bit level
  • How to replace multiple instances of a sub strings in a string using a for loop (in a function)?
  • py2neo cypher create several relations to central node in for loop
  • [python-3]TypeError: must be str, not int
  • How to exit/terminate a job earlier and handle the raised exception in apscheduler?
  • python, print intermediate values while loop
  • python to loop over yaml config
  • D3.js is not recognized by PyCharm
  • Access the regularization paths obtained from ElasticNetCV in sklearn
  • Pattern table to Pandas DataFrame
  • Get the earliest date from a column (Python Pandas) after csv.reader
  • Get SystemError: Parent module '' not loaded, cannot perform relative import when trying to import numpy in a Cython Ext
  • Bash or Python : Append and prepend a string recursively in all .tex files
  • Changing a certain index of boolean list of lists change others, too
  • complex dataframe filtering request on the last occurence of a value in Panda/Python [EDIT]
  • How to repeatedly get the contents of a Text widget every loop with tkinter?
  • How to call the tornado.queues message externally
  • How can I use regex in python so that characters not included are disallowed?
  • Discarding randmly scattered empty spaces in pandas data frame
  • Get sums grouped by date by same column filtered by 2 conditions
  • Element disappears when I add an {% include %} tag inside my for loop
  • Django Rest Framework with either a slug or a pk lookup field for the DetailAPIView
  • Flask doesn't stream on Lambda
  • Generate all permutations of fixed length where the elements come from two different sets
  • Making function for calculating distance
  • How to handle multiprocessing based on the limit of CPU's
  • Django - static files is not working
  • Remove x axis and y axis black lines with matplotlib
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org