# Set upper bound for pgfplots axis width?

Is there anything like

\pgfplotsset{
every axis/.append style={
width = 0.9\linewidth,
max width = 4in
}}


Suppose I have a document with hundreds of tikzpicture environments, each having plots that use pgfplots axis environments. For simplicity of my question, none are in floats. Half of these appear individually as their own "paragraph". Half of them appear inside narrow environments, such as side by side minipages.

I'd like to use something like width = 0.9\linewidth, except that this would make the images which appear in their own paragraphs much too wide. So I'd like to put an upper bound on the width. Doesn't look like max width works as a key for this.

I am hoping to avoid setting width locally in any of the images.

You could use

width = {ifthenelse(.9\linewidth>3in,3in,.9\linewidth)}


Example:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{
compat=1.13,
every axis/.append style={
width = {ifthenelse(.9\linewidth>3in,3in,.9\linewidth)}
}
}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\end{axis}
\end{tikzpicture}

\begin{minipage}[b]{5cm}
\begin{tikzpicture}
\begin{axis}