Quantcast
Channel: User tdy - Stack Overflow
Browsing latest articles
Browse All 99 View Live

Image may be NSFW.
Clik here to view.

Answer by tdy for Fixed ylabel space (aligned y-axis) across multiple figures

In these cases, I just add empty axes at the left edge of each figure. I'm sure there are more sophisticated ways, but I find this to be simplest:fig1 with blank axes at left locationfig1, ax =...

View Article



Image may be NSFW.
Clik here to view.

Answer by tdy for How can I add text to the same position in multiple...

Use ax.annotate with axes fraction coordinates:fig, axs = plt.subplots(1, 2)axs[0].plot([0, 0.8, 1, 0.5])axs[1].plot([10, 300, 200])for ax in axs: ax.annotate('text', (0.05, 0.9), xycoords='axes...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for bar labels with new f-string format style

How can I make bar_label work with new style formatting like percentages, thousands separators, etc?As of matplotlib 3.7The fmt param now directly supports {}-based format strings, e.g.:# >=...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for How can I create a plot to visualize the 68–95–99.7 rule?

The line version can be implemented using vlines, but note that your reference figure can be better reproduced using fill_between.Line versionInstead of axvline, use vlines which supports ymin and ymax...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for Animate labels using FuncAnimation in Matplotlib

Two problems overall:The annotation text never gets updated in updatefig()The canvas gets cleared+blitted, which wipes out annotationsFive steps to resolve:Remove fig.clear() to preserve...

View Article


Image may be NSFW.
Clik here to view.

Answer by tdy for Plotting a 3-dimensional superball shape

When plotting a regular sphere, we transform positive and negative coordinates differently:Positives: x**0.5Negatives: -1 * abs(x)**0.5For the superball variants, apply the same logic using np.sign and...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for Add ONLY the total values on top of stacked bars

As Trenton points out, bar_label is usable only if the topmost segment is never zero (i.e., exists in every stack) but otherwise not. Here are examples of the two cases.If the topmost segment is never...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for Pandas DataFrame: replace all values in a column, based on...

TLDR— Here is some usage guidance, including some methods that haven't been mentioned yet:Use caseRecommendedExampleSpeedDataFrame.locdf.loc[df['A'] < 10, 'A'] = 1Method chainingSeries.maskdf['A'] =...

View Article


Image may be NSFW.
Clik here to view.

Answer by tdy for What is the meaning of "multiple" parameter in Seaborn's...

You can think of it like this:OptionMeaningExplanationlayerOriginal densityThe densities are overlaid on each other, so the y-value just represents the original density of each curve.stackStacked...

View Article


Image may be NSFW.
Clik here to view.

Answer by tdy for Draw a line to connect points between subfigures

ConnectionPatch works fine with subfigures, but as @JodyKlymak points out, the patch should be removed from layout calculations via set_in_layout(False).Here is an example connecting (4, 8) on the...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for Plot horizontal bars using seaborn.objects interface (v0.12)

For completeness, to replicate the original horizontal barplot behavior for wide-form data:# old interfacesns.barplot(data=df, orient="h")We now need to melt into long-form and explicitly swap x/y:#...

View Article

Image may be NSFW.
Clik here to view.

Plot horizontal bars using seaborn.objects interface (v0.12)

In the original API, barplot provided an orient parameter to swap bar orientation:import pandas as pd, numpy as np, seaborn as snsdf = pd.DataFrame(data=np.random.randint(10, size=(3, 5)),...

View Article

Answer by tdy for Zip to longest length in Julia (like Python's zip_longest)

This approach seems to be fast(est):function zip_longest(iters...) filled = [[i; fill(nothing, maximum(length, iters) - length(i))] for i in iters] return zip(filled...)endIt will fill the iterators to...

View Article


Zip to longest length in Julia (like Python's zip_longest)

Base.Iterators.zip terminates at the shortest iterator, so here Carol/David/100 get dropped:julia> a = [1, 2]julia> b = ["Alice", "Bob", "Carol", "David"]julia> c = [90, 85, 100]julia>...

View Article

Answer by tdy for How to invert background color based on the light/dark...

Mr. J's approach will invert .bg-body and .text-body globally. I'm not sure how useful that is because you could (should) just use the opposite theme in that case.Nested color modes (JS)I would use...

View Article


Image may be NSFW.
Clik here to view.

Answer by tdy for Style background color of dataframe cells based on rule

df.style.applymap operates elementwise, so the styling function expects only 1 cell (not a dataframe)100-(100-a)-(100-b) can be simplified to just a+b-100So the styling function should look something...

View Article

Answer by tdy for Getting specified range of an array in Nunjucks

It doesn't work for this case. That slice doesn't work like JS slice.Actually it is the JS slice, and we can use it directly in NJK templates.Note the dot syntax:{% set array = ['a', 'b', 'c', 'd',...

View Article


Image may be NSFW.
Clik here to view.

Answer by tdy for How to add wave shape at the bottom of Bootstrap card

First create an SVG of your preferred wave shape. I won't advertise any specific app/service, but there are lots of free SVG online generators and offline editors.Here I've created one resembling your...

View Article

Answer by tdy for Pandas read_csv() converts integer columns to float if...

I cannot specify a dictionary for dtype of each column when using read_csv() as each dataset is different and it'll be a lot of manual work.In this case, use convert_dtypes which will automatically...

View Article

Answer by tdy for Distribute data from list into column in panda dataframe

Pass 25 of each element (users*25) into np.random.Generator.choice (or the deprecated np.random.choice) and set replace=False:users = list('abcd')X = pd.DataFrame()rng =...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for Change the cell size/width of imshow or similar function

As Jody commented, if you only want to clip the outermost cells, a quick shortcut is to change the axes limits:ax.set_xlim(0, 5)But in the more general case, use pcolormesh for custom grids. Define the...

View Article


Image may be NSFW.
Clik here to view.

Answer by tdy for Python equivalent to R's layout() for arbitrary grids

The simplest counterpart is plt.subplot_mosaic, which is a convenience wrapper for making custom gridspecs:Each character is a column, and each line is a rowEach unique letter gets grouped into one...

View Article


Answer by tdy for Why isn't the .sr-only class working in Bootstrap 5?

This was one of the breaking changes in v5:[Breaking]"Screen reader" classes are now "visually hidden" classes.Renamed .sr-only and .sr-only-focusable to .visually-hidden and...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for Color palette of seaborn scatterplot is not working

palette is tied to hue, so change c to hue:ax = sns.scatterplot(x=x, y=y, s=15, hue=y, palette="YlOrBr", legend=False)

View Article

Image may be NSFW.
Clik here to view.

Plot regression confidence interval using seaborn.objects interface (v0.12)

How can I use the objects API to plot a regression line with confidence limits (like sns.regplot / sns.lmplot)?Based on the so.Bandfmri example, I thought it would be something like this:import seaborn...

View Article


Image may be NSFW.
Clik here to view.

Answer by tdy for Grouped bar plot in MATLAB based on column values in a table

I want to group the bars by SampleSite, label them by SampleName, and color them by Category.pivot your current "long" table into a "wide" table:One SampleSite (group) per rowOne Category (color) per...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for adding regression line to a plot given its intercept and slope

New in matplotlib 3.3.0plt.axline now makes it much easier to plot a regression line (or any arbitrary infinite line).Slope-intercept formThis is simplest for regression lines. Use np.polyfit to...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for How to display custom values on a bar plot

New in matplotlib 3.4.0There is now a built-in Axes.bar_label to automatically label bar containers:ax = sns.barplot(x='day', y='tip', data=groupedvalues)ax.bar_label(ax.containers[0]) # only 1...

View Article

Image may be NSFW.
Clik here to view.

Answer by tdy for Why doesn't sns.barplot legend show all values?

As of seaborn 0.13.0, legend entries will sometimes be hidden by default.There is now a legend parameter to control how much is shown:legend=...Behavior"brief"Numeric hue and size variables will be...

View Article



Image may be NSFW.
Clik here to view.

Answer by tdy for Remove gaps between subplots_mosaic in matplotlib

This is not caused by subplot_mosaic but because a layout was specified. If you use constrained or tight layout, the layout manager will supersede the custom adjustments.Remove the layout manager and...

View Article

Comment by tdy on React Hooks useState() with Object

stackoverflow.com/help/ai-policy

View Article

Comment by tdy on error while loading shared libraries: libicui18n.so.68

Your apt command is for Ubuntu/Debian. Then your brew command is for Mac. Not to mention the question was about Arch/Manjaro...

View Article

Comment by tdy on How to convert df to csv file using to_csv without...

FYI sep=',' is the default so you don't even need to specify it.

View Article


Comment by tdy on Is it possible to halt the the code in Selenium Python for...

Was any of this AI-generated?

View Article

Comment by tdy on How to Fix NO_SECRET warning thrown by Next-Auth

Was any of this AI-generated?

View Article

Comment by tdy on How to display the value on horizontal bars

@sourcream something like ax.bar_label(bars, labels=[x if x else '' for x in bars.datavalues])

View Article


Comment by tdy on Dynamically include specific directories and exclude others...

Was any of this AI-generated?

View Article


Comment by tdy on How to get the full Sales by Product/Service Detail Report...

Was any of this AI-generated?

View Article

Comment by tdy on 'socket.http' module isn't found when using require

Please do not upload images of code/data/errors.

View Article

Comment by tdy on How to consent to cookies via Android webview

Was any of this AI-generated?

View Article

Comment by tdy on How to type useNavigation with nested navigators in React...

stackoverflow.com/help/ai-policy

View Article


Comment by tdy on I am doing explorative data analysis from the dataset

stackoverflow.com/help/ai-policy

View Article

Comment by tdy on How to convert multiple columns from string to integer in...

FYI if you load your dataframe using the "thousands" parameter, you won't have to convert those columns at all (they'll be correctly detected as int64 in the first place): pd.read_csv('filename.csv',...

View Article


Comment by tdy on How to deploy django app with channels and websocket on...

stackoverflow.com/help/ai-policy

View Article

Comment by tdy on How to implement 2FA in Laravel with Inertia.js and Vue 3?

Was any of this AI-generated?

View Article

Browsing latest articles
Browse All 99 View Live




Latest Images